Ok, so in my class I have to make a guess the number game using these guidelines:
Level 1. Write a Python program that asks the user to guess a number between 0 and 100 and give feedback that tells the user the guess was too high or too low until they correctly guess the number.
Level 2. After the user correctly guesses the number, add output telling the user how many guesses it took.
Level 3. The range for guessing changes after each guess. For example if the user’s first guess is 50 and the feedback is that the guess was to high, the next guess should be between 0 and 50. To help the user, update the new range for the guess every time they are asked for another guess.
Level 4. What if the user accidentally types a number that is not within then range? Provide feedback that the guess was outside the range and then do not change the range for the guesses when prompted for another guess. Let’s also not count a guess outside the range in their total number of guesses.
Level 5. After the user correctly guesses the number, ask if they would like to play again. If the first letter of their response is ‘y’ or ‘Y’ start over with a range from 0 to 100 again.
Level 6. Each time the user guesses the correct number include feedback giving the fewest number of guesses needed to correctly guess the number (low/best score). Hint: You can initialize the low score at a really high number like 100 guesses.
So I need help on level 2, 3, 4, and 6.
Here is what I have so far:
import random def main(): print "" number = input("I have a number between 1 and 100. Can you guess my number? Please type your first guess: ") guess(number) def guess(number1): randomNumber = random.randrange(1, 100) correct = False while not correct: if number1 > randomNumber: print "Too high. Try again." print "" elif number1 < randomNumber: print "Too low. Try again." print "" elif number1 == randomNumber: break number1 = input ("What number do you guess? ") if number1 == randomNumber: playAagain = raw_input ("Excellent! You guessed the number! Would you like to play again (y or n)? ") if playAagain == "y" or "Y": main() main()