Question

In: Computer Science

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 integ

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!

Solutions

Expert Solution

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)


Related Solutions

Project 5-3: Guessing Game Create an application that lets a user guess a number between 1...
Project 5-3: Guessing Game Create an application that lets a user guess a number between 1 and 100. Console Welcome to the Guess the Number Game ++++++++++++++++++++++++++++++++++++ I'm thinking of a number from 1 to 100. Try to guess it. Enter number: 50 You got it in 1 tries. Great work! You are a mathematical wizard. Try again? (y/n): y I'm thinking of a number from 1 to 100. Try to guess it. Enter number: 50 Way too high! Guess...
Write a C++ console application to simulate a guessing game. Generate a random integer between one...
Write a C++ console application to simulate a guessing game. Generate a random integer between one and 100 inclusive. Ask the user to guess the number. If the user’s number is lower than the random number, let the user know. If the number is higher, indicate that to the user. Prompt the user to enter another number. The game will continue until the user can find out what the random number is. Once the number is guessed correctly, display a...
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the...
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the user to guess four numbers.  Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess, the randomly determined four-digit number, and the amount of points the user has won as follows: No matches 0 points Any one digit matching 5 points Any two digits matching 100 points Any three digits matching 2,000 points All four...
JAVA PROGRAM Write program that will prompt user generate two random integers with values from 1...
JAVA PROGRAM Write program that will prompt user generate two random integers with values from 1 to 10 then subtract the second integer from the first integer. Note, if the second integer is greater than the first integer, swap the two integers before making the subtraction.Then prompt user for the answer after the subtraction. If the answer is correct, display “Correct”otherwise display “Wrong”.You will need to do this in a loop FIVE times and keep a count of how many...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT