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

In repl.it Python: Develop a Python solution using Classes for the follow proble

ID: 3845631 • Letter: I

Question

In repl.it Python:

Develop a Python solution using Classes for the follow problem:

Create a class that defines a guessing game,

the game should have variables to define the range of values, such as starting at 1 and ending at 100.

within those range values a random number should be generated.

the class should ensure that the numbers entered by the user are between the range values, and are numbers, and not strings

The class should have functionality to respond to a users input with a higher or lower or correct answer, when comparing the user entered number with the random number generated.

When the user is correct, the program should print off the number of times the user was incorrect.

Create an instance of the class defined, that will use a range of 1 - 100.

Explanation / Answer

The code is given below :

import random

BOUNDS = (1, 100)
TRIES_ALLOWED = 5

the_number = random.randint(*BOUNDS)

print(" Welcome to 'Guess My Number between 1 to 100'! ")
print("I'm thinking of a number between %d and %d." % BOUNDS)
print("Try to guess it in less attempts as possible. ")

for tries in range(TRIES_ALLOWED):
guess = int(input("please Take a guess: "))

if guess > the_number:
print("Lower...")
elif guess < the_number:
print("Higher...")
else:
print("Your guess is right! The number was %d" % (the_number))
print("And it only took you %d tries! " % (tries + 1))
break
else:
print("You failed to guess in time and please try again ! ")

try:
input("Press the enter key to exit from the game.")
except:
pass

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote