What's wrong with this code? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

What's wrong with this code?

I know I need to feed an input for condition that's not entirely why this code is going wrong. The output conveniently goes right with else work work. I'm still learning so tried datetime.today().day to define "today" but that didn't seem to work either. Why? https://code.sololearn.com/cHUOM7dyK6OP/?ref=app

22nd May 2019, 12:47 PM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
6 Réponses
+ 4
Akhil Padmanabhan you should give a number to if statement not a string ! because: 22 != '22' so... use: if today == 22: instead of: if today == 22: full code working: from datetime import datetime today = datetime.today().day if today == 22: print("Party!") elif today == '24': if condition == ("headache"): print("I should have a cup of tea") else: print ("Call Debbie") else: print ("work work work work work work.. I love you Riri") print (today ) #what's wrong with code? Please comment.
22nd May 2019, 12:48 PM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 4
Akhil Padmanabhan first try this code... from datetime import datetime today = datetime.today().day if today == 22: print("Party!") elif today == 24: if condition == ("headache"): print("I should have a cup of tea") else: print ("Call Debbie") else: print ("work work work work work work.. I love you Riri") #what's wrong with code? Please comment.
22nd May 2019, 12:55 PM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 4
Akhil Padmanabhan you can read a good tutorial for taking input here: https://www.geeksforgeeks.org/taking-input-in-JUMP_LINK__&&__python__&&__JUMP_LINK/ or instead, read sololearn tutorial: https://www.sololearn.com/learn/Python/2426/ I hope I was helpful
22nd May 2019, 1:05 PM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 4
Akhil Padmanabhan you are welcome! :)
22nd May 2019, 1:53 PM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 1
Alessio Yo man that's working totally.. Now I want to assign an input for condition how do i do that? from datetime import datetime today = datetime.today().day condition = input("Are you having a headache?" ) if today == 25: print("Party!") elif today == 22: if condition == ("Yes"): print("I should have a cup of tea") else: print ("Call Debbie") else: print ("work work work work work work.. I love you Riri")
22nd May 2019, 12:58 PM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
+ 1
Alessio Hell yea.. Thank you so much!!
22nd May 2019, 1:50 PM
Akhil Padmanabhan
Akhil Padmanabhan - avatar