+ 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
8 odpowiedzi
+ 4
it doesn't work because u don't tell him to work .
call your functions ;)
+ 2
You need to call the functions at the end of your code do
name()
mood()
+ 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 ! 😃
0
Also, I've tried using this:
if mood.lower() == "sad"
#blah blah
0
@James, I've titled the code "Can someone fix this?" in the playground
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