-3

Returns an error on restart 'yes' is not defined. A noob to python, so not very sure what's wrong here.

restart = input("Would you like to play again? ").lower
if restart == ("yes"):
    print("Restarting.. ")
    main()
elif restart == ("no"):
    print("Bye! ")
    exit()

main()

I want for when the user types yes or no, it either exits the program or re-runs main().

martineau
  • 119,623
  • 25
  • 170
  • 301
Ewanziak
  • 73
  • 3
  • 4
    What version of Python are you using? I suspect you might be using Python 2, in which case you need `raw_input`, not `input`. – khelwood Mar 27 '19 at 15:49
  • 5
    1. Show us all the relevant code (this is not even a [mcve]) 2. If you are using Python 2 you should use `raw_input` instead of `input `3. you mean `.lower()`, not `.lower`, 4. You seem to use an infinite recursion here, which is bad in the long run. – DeepSpace Mar 27 '19 at 15:50
  • 1
    Hello friend. You want to use `raw_input` instead of `input` in Python 2. `input` is actually trying the evaluate the input as Python code, which is very rarely what anybody wants. This was changed in Python 3. – Jeremy Mar 27 '19 at 15:50
  • @Jeremy Thank you! It works now :) – Ewanziak Mar 27 '19 at 16:02
  • 1
    Possible duplicate of [input() error - NameError: name '...' is not defined](https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined) – mkrieger1 Mar 27 '19 at 17:41

1 Answers1

1
 restart = raw_input("Would you like to play again? ").lower()
 if restart == ("yes"):
    print("Restarting.. ")
    main()
 elif restart == ("no"):
  print("Bye! ")
  exit()

 main() 

since you are using python 2 your code should be like that

salah
  • 106
  • 2
  • 12