The standard way of repeating code is to use a
while loop. There are two styles: the 'test first' and 'test last' methods.
# a test-first loop: set the sentinel and repeat until sentinel is false
repeat = True
while repeat:
print "You lose!"
if raw_input("Play again? (y/n) ") == "n":
repeat = False
# a test-last method: repeat until the test fails. This method makes more sense to me but is frowned on by some purists.
while True:
print "You lose!"
if raw_input("Play again? (y/n) ") == "n":
break
Jeff
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
Offline 608 posts
since Jul 2006