+ 2
If: else:
hi.i tried this code in python: nume=input("") if nume.endswith("ana"): print(nume + " - banana") if nume.endswith("tin"): print(nume+" - mandarin") else: print("you are lucky") why does it print all the time the "you are lucky"? if i type name "diana", it should only print "diana - banana", but it executes also the "else" print
2 Respostas
+ 15
Because it first does the first 'if' if it's true it goes to the second 'if' which will be false and so it will do the 'else' as well.
I suggest using 'elif' instead of that second 'if' and that 'else'.
+ 2
thank you... from the first chapters and i already forgot)