-6
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")

Whats wrong with this code?? It says in the idle shell syntax error. The last elif statement isn't working.

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
Nhoward292
  • 11
  • 6

1 Answers1

3

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

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186