This is for a game. The game asks the user if s/he would like to play again. If not, the program should just exit. If yes, the entire game is repeated and asks to play again, and so on.
while True:
print "*game being played*"
# prompt to play again:
while True:
replay = raw_input("Play again? ")
print replay
if replay.lower == "yes" or "y":
break
elif replay.lower == "no" or "n":
sys.exit()
else:
print "Sorry, I didn't understand that."
However, when I actually execute this code it acts as if every answer input is a yes (even "aksj;fakdsf"), so it replays the game again.
.
When I changed the code to first consider no instead of yes:
if replay.lower == "no" or "n":
sys.exit()
I get the error
Traceback (most recent call last):
File "C:/Python27/Programs/replay game.py", line 18, in <module>
sys.exit()
NameError: name 'sys' is not defined
This might have something to do with the fact I don't actually know what sys.exit() does but just found it while googling "how to exit program python".