# Guess my number # # The computer picks a random number between 1 and 100 # The player tries to guess it and the computer lets # the player know if the guess is to high, to low # or right on the money
import random print("\tWelcome to 'Guess My Number'!") print("I'm thinking of a number between 1 and 100.") print("Try to guess it in as few attempts as possible.\n") # set the initial values the_number = random.randint(1,100) guess = int(input("Take a guess: ")) tries = 1 # Guessing loop while guess != the_number: if guess > the_number: print("Lowere...") else: print("Higher...") guess = int(input("Take a guess: ")) tries += 1 print("good job") input("\n\nPress the enter key to exit.") This is a program from "Python for the absulute beginner(which I am). End of the chapter is a challenge that asks me to limit the number of guesses the player gets. If he/she fails to guess the number after a certain number of attempts then it displays a message about his failure.It needs to be a while loop cause it the topic I'm at.Can anyone give me some help on where to put the loop.When i put it in with the "if guess>the_number" loop, the program either prints higher or lower continuously(continuous loop I imagine) or it gives me the answer whether its right or wrong after a couple guesses.Any help will be appreciated. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor