Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab 10 Random Number Guessing Game Objectives: Practice random number generation

ID: 3673435 • Letter: L

Question

Lab 10 Random Number Guessing Game Objectives: Practice random number generation, loop, and decision structures. Design a Python program that generates a random number in the range of 1 through 100 (inclusively), and asks the user to guess what the number is. Keep that number hidden from the user. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the number, the program should display "Too low, try again." If the user's guess matches that hidden random number, the program should congratulate the user and then display the number of guesses that the user makes. You will need to use a function from the random module to generate a random number. User interface specifications: Input The program prompts users to enter guesses. Clearly tell users that their input number must be in the range [1,100]; i.e., from 1 to 100 inclusively Output Feedbacks to users about their guesses, as specified in the first paragraph of this assignment sheet. Submission: The name of submitted file must be in the following format: lab10_yourfirstname_yourlastname.py Due at 3/3/2015 (Th) 11:55 pm Total points: 20 10 if your program runs correctly, including feedbacks to users 10 if your submission follows all of the specifications in this assignment sheet

Explanation / Answer

from random import randint
number = randint(1,100)
count = 0
while(1) :
        count = count + 1
        guess = input("Enter your guess")
        if(guess == number):
                print "number guessed correctly"
                print "the number of guesses user made is : ",count
                break
        elif guess > number :
                print "Too high, try again"
        else :print "Too low, try again"