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

this is a python 3.4 question. Step 1: Develop new widget \"Game\" that implemen

ID: 3692660 • Letter: T

Question

this is a python 3.4 question.

Step 1: Develop new widget "Game" that implements a number guessing game. When started, a secret random number between 0 and 9 is chosen. the user is then requested to enter number gueses. Your GUI (graphical user interface) should have an Entry widget for the user to type the number guess and a Button widget to enter the guess. If the guess is correct, a sepearte window should inform the user of that. The user should be able to enter guesses until he makes the correct guess.
Step 2: In Problem 9.20 (the above), pressing the "enter/return" key on your keyboard after entering a guess in the entry is ignored. Modify the Game GUI so that pressing the key is equivalent to pressing the button.
Step 3: Modify the widget Game from Problem 9.21 so that a new game starts automatically when the user has guessed the number. The window informing the user that she made the correct guess should say something like "Let's do this again..." Note that a new random number would have to be chosen at the start of each game. please note that the answer that is currently on chegg does not render/work, so i am asking again.

Explanation / Answer

program :

import random
import time
import sys
import os
MIN_NUMBER = 1
MAX_NUMBER = 10
def get_random(min, max):
print "Coming up with a number."
time.sleep(2)
random_number = random.randint(min, max)
print "Got it!"
return random_number
def to_int(x):
try:
x = int(x)
return x
except ValueError:
print "That is not a whole number."
return False
def how_close(guess, right_answer):
return right_answer - guess
def hi_low_done(delta):
if delta < 0:
print "Guess lower."
return False
elif delta > 0:
print "Guess higher."
return False
else:
print "You got it!"
return True
os.system('cls')
print "Welcome. I am the Oracle."
print "I will think of a number between %s and %s. Guess it and you will win!" % (MIN_NUMBER, MAX_NUMBER)
while True:
user_answer = raw_input("Ready? <y/n> ")
if user_answer.lower() == 'y' or user_answer.lower() == 'yes':
print "Great! Let's go."
break;
elif user_answer.lower() == 'n' or user_answer.lower() == 'no':
print "Okay. Consult the Oracle when you are ready."
sys.exit()
oracles_number = get_random(MIN_NUMBER, MAX_NUMBER)
number_of_guesses = 0
while True:
number_of_guesses = number_of_guesses + 1
user_answer = raw_input(" Guess> ")
user_answer = to_int(user_answer)
if user_answer:
delta = how_close(user_answer, oracles_number)
done = hi_low_done(delta)
if done:
break;