In: Computer Science
In Python
Guessing Game Application
Create the Guessing Game Application. The application should receive two integers from the user, namely minimum and maximum and generate a random integer from minimum through maximum, inclusive. It then should give the user five chances to guess the integer. Each time the user makes a guess, the application should display one of two messages: “Guess higher” or “Guess lower”. If the user guesses the generated number the application should let her/him know and also display the number of chances that were required for the user to guess the number. If the user is not able to guess the number in five attempts the application should display “Game over!” and indicate the correct number. The program output should be formatted as shown in the Sample Run.
Note: Python provides a function for generating a random integer within a given range. The function randint(minimum, maximum) which is defined in the random module, returns a random integer that is between minimum and maximum, including the bounds themselves. Before you can use the function, you need to import it as follows at the beginning of your code: from random import randint
SAMPLE RUN
Enter a small positive number: 3
Enter a large positive number: 6
Enter your guess: 3
Guess higher
Enter your guess: 5
Guess higher
Enter your guess: 6
You've got it in 3 tries!
output1:
output2:
Raw_code:
# importing randint function from random module
from random import randint
# taking minium and maximum number form user
minimum = int(input("Enter a small positive number: "))
maximum = int(input("Enter a large positive number: "))
# generating random number b/w minimum and maximum numbers using
randint function
number = randint(minimum, maximum)
# variable for storing chances, intialized to one
chance = 1
guess = 0
# while loop runs until 5 chances are over or user guess the
number
while number != guess and chance <= 5:
# taking user guess and storing in guess
guess = int(input("Enter your guess: "))
# if user guess is less than random number
if guess < number:
print("Guess higher")
# if user guess is greater than random number
elif guess > number:
print("Guess lower")
# if user is correct, printing no of chances
else:
print("You've got it in {0:1d} tries!".format(chance))
# incrementing chance by 1 for each while loop iteration
chance += 1
# if user doesn't guess the number
if chance > 5:
print("Game over!")
print("Number is :", number)