By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 464,767 Members | 1,098 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,767 IT Pros & Developers. It's quick & easy.

# High Low game

 P: 2 I am trying to write a program in Python for a High Low guessing game. It has to tell the person if their guess is higher or lower, also keep track of their guesses, it also needs to ask them if they would like to play again and loop back to the beginning when done. I have most of it done but I am having problems with making it play again. This is what I have so far: Expand|Select|Wrap|Line Numbers # Guess My Number # The computer picks a random number   def begin ():  import random print "\tWelcome to 'Guess my Number'!:" print "\nI'm thinking of a number between 1 and 100." print "Try to guess it in as few attempts as possible.\n"   def guess_num(num, max_guesses):     # guessing loop     tries = 0     while True:         guess = int(raw_input("Take a guess: "))         tries += 1         if guess > num:             print "Lower..."         elif guess < num:             print "Higher..."         else:             print "You guessed it! The number was", num             print "And it only took you %d tr%s!\n" % (tries, ['ies', 'y'] [tries==1 or 0])             return           if tries == max_guesses:             print "You have had %d guesses. Game over." % max_guesses             return         play = raw_input("Do you want to play again? Y/N")         if play == "Y":              begin ()         if play == "N":              print "Well you are no fun. Bye."         the_number = random.randrange(1,100) max_guesses = 5 guess_num(the_number, max_guesses) Any help would be greatly appreciated. Feb 13 '12 #1
Share this Question
2 Replies

 100+ P: 126 begin() never calls guess_num(). Feb 13 '12 #2

 P: 2 Okay so that is where I went wrong. Thank you for the help. Feb 13 '12 #3

### Post your reply

Sign in to post your reply or Sign up for a free account.