High Low game

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TiffiniLeigh
    New Member
    • Feb 2012
    • 2

    High Low game

    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:

    Code:
    # 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.
    Last edited by bvdet; Feb 13 '12, 04:17 PM. Reason: Add code tags
  • Smygis
    New Member
    • Jun 2007
    • 126

    #2
    begin() never calls guess_num().

    Comment

    • TiffiniLeigh
      New Member
      • Feb 2012
      • 2

      #3
      Okay so that is where I went wrong. Thank you for the help.

      Comment

      Working...