In my program I want to interact with user and ask him to press specific letters to do some things (I think that logic of this game is not relevant for my question). When I start game and as first letter I press 'q' program exit immediately, but when I play for a while (use few times 'g' and 'r') I have to press few times 'q' too before I could exit program (Every time I'm getting the same prompt as on the beginnig of the game "Enter g to start ... ") I'm using Canopy and Python 2.7.
t_h = ''
def pg(wl):
global t_h
result = raw_input("Enter g to start new game, r to replay last game, or q to end game: ")
possible_choices = ["g", "r", "q"]
if result in possible_choices:
if result == 'g':
t_h = dh(n)
ph(t_h, wl, n)
if result == 'r':
if t_h == '':
print 'You have not played a game yet. Please play a new game first!'
else:
ph(t_h, wl, n)
if result == 'q':
return None
else:
print "Invalid letter."
return pg(wl)
qto get out of it. Replace the recursion with a loop.return Nonewithexit().