Python Programming Error, Elif Statment Syntax Error Simple Code
name=input('Hello person, Whats your name?') print('Hello', name) print('Do you want to hear a story?', name) choice=input('Yes, No?') if choice==('yes' or 'yes ' or 'Yes' or 'Yes
Solution 1:
This is a petty indentation issue, your print statements for the if
blocks are not indented right and so the elif
seems to be out of place. Note that python keeps track of logical blocks by the indentation.
name=input("Hello person, Whats your name?")
print("Hello", name)
print("Do you want to hear a story?", name)
choice=input("Yes, No?")
if choice==("yes" or "yes " or "Yes" or "Yes "):
print("Ok", name,", listen up")
print("There was once an old, old house at the top of a hill Sooooo high it was above the clouds")
choice2=input("What do you want to call the house?")
print("The old,",choice2,"was once owned by an old lady. ")
elif choice==("maybe"):
print("You found an easter egg, congrats. PS this does nothing")
As already pointed out, if choice==("yes" or "yes " or "Yes" or "Yes ")
is wrong, use if choice.lower().strip() == "yes"
instead, or if choice in ("yes", "yes ", "Yes", "Yes ")
.
If in case this is python 2, input
will throw an error, use raw_input
instead.
Also print
with multiple statements will throw errors as well if used like a function, so change them from print(statement_x, statement_y, statement_z)
to print statement_x, statement_y, statement_z
Post a Comment for "Python Programming Error, Elif Statment Syntax Error Simple Code"