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...
5 Réponses
+ 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')
+ 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.
+ 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
+ 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.
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')