from random import randint def playRound(): secret = randint(1,100) guess = int(raw_input("Guess the number: ")) while guess != secret: # wrong answer if guess > secret: print "No. Lower" elif guess < secret: print "No. Higher" # get a new guess guess = int(raw_input("Guess the number: ")) print "Yes. Congratulations" def askYesNo(prompt): response = '' while response not in ('yes', 'no'): response = raw_input(prompt).strip().lower() return response == 'yes' wantsToPlay = True # will play at least one time while wantsToPlay: playRound() wantsToPlay = askYesNo("Would you like to play again? ") print 'Thanks for playing. Goodbye'