Why does a code like this not work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does a code like this not work?

Code: def name(): name = input("What is your name?") #1st issue: This won't be asked def mood(): mood = input("How are you feeling?") #1st issue if mood == "Sad" or mood == "sad": print("Aww") #2nd issue: Sometimes no matter what you type this is what the output will be elif mood == "Happy" or mood == "happy": print ("Yay") else: print("What does that mean?") #2nd issue

8th Aug 2017, 12:22 AM
ZackeryE21
ZackeryE21 - avatar
6 Answers
+ 4
it doesn't work because u don't tell him to work . call your functions ;)
8th Aug 2017, 12:45 AM
TheAtito
TheAtito - avatar
+ 2
You need to call the functions at the end of your code do name() mood()
8th Aug 2017, 12:30 AM
MemeSenpai
MemeSenpai - avatar
+ 1
I don't know Python but I can see that you are using if mood == "Sad" or mood == "sad" Instead you this just downcase the input String and use it in if statement like :- if mood == "sad" Another way to make your code efficient is use of case statement... with this you reduce multiple elsif statements ! 😃
8th Aug 2017, 4:23 AM
Ekansh
0
Also, I've tried using this: if mood.lower() == "sad" #blah blah
8th Aug 2017, 12:25 AM
ZackeryE21
ZackeryE21 - avatar
0
@James, I've titled the code "Can someone fix this?" in the playground
8th Aug 2017, 8:12 PM
ZackeryE21
ZackeryE21 - avatar
0
Thank you for the fix. I appreciate it! I'm sure I'll need more help in the future, so, see you around. :P
8th Aug 2017, 9:22 PM
ZackeryE21
ZackeryE21 - avatar