简体   繁体   中英

"yes" not defined? A little confused

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() .

 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM