Can someone tell me why Elif is not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone tell me why Elif is not working?

Code is as follows: Print('Do you love love me? Y = yes and N = no') If input() == 'y': print('Awe I love you too!') elif input() == 'n': print('Nice try nerd we both know you do') Indentions are correct in the actual idle For some reason if I type y when given the prompt it executes the print statement but if I input n nothing happens ... it's for my gf I was bored...

12th Aug 2021, 4:29 AM
J
5 Answers
+ 2
the program doesn't catch the input in the conditions. try putting input() function in a variable and then compare that variable in conditions. standard keywords are usually in lowercase, never in camelcase. as you did with if and print statement. thanks for Simon Sauter for correction. here's the working program print('Do you love love me? y = yes and n = no') a = input() if a == 'y': print('Awe I love you too!') elif a == 'n': print('Nice try nerd we both know you do')
12th Aug 2021, 4:38 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 1
The issue is that you ask for input *within* the if and elif statements. This way you need two inputs, one for the if statement and one for the elif statement (the second input is optional if the if statement evaluates to true). Start by assigning the input to a variable, then check the value in the if and elif statements.
12th Aug 2021, 4:34 AM
Simon Sauter
Simon Sauter - avatar
+ 1
It's ok. But you need to make this: question= input('Do You love me? Y=yes and N=no') question = question.lower() if question == 'y': print('Awe I love You too') elif question=='n': print('Nice try nerd wey both know You do') Let me know if it works
12th Aug 2021, 4:40 AM
Cesar Torres
Cesar Torres - avatar
+ 1
Rellot's screwdriver One small naggle: On sololearn it doesn't matter because you have to give the input before the code runs. But you should print the question before asking for input.
12th Aug 2021, 4:41 AM
Simon Sauter
Simon Sauter - avatar
0
I'm stupid lol I changed it to this and it worked x = input(Do you love love me? Y = yes and N = no') If x == 'y': print('Awe I love you too!') elif x == 'n': print('Nice try nerd we both know you do')
12th Aug 2021, 5:03 AM
J