PYTHON: Programming Exercise 8.5 Write a GUI-based program that plays a guess-the-number game in which the roles of the

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

PYTHON: Programming Exercise 8.5 Write a GUI-based program that plays a guess-the-number game in which the roles of the

Post by answerhappygod »

PYTHON: Programming Exercise 8.5 Write a GUI-based program thatplays a guess-the-number game in which the roles of the computerand the user are the reverse of what they are in the CaseStudy of this chapter. In this version of the game, thecomputer guesses a number between 1 (lowerBound) and 100(upperBound) and the user provides the responses.
Be sure to use the field names provided in the comments in yourstarter code. Please provide the correct code with indentation.
When I run my code I get this error, pleasehelp!!
Errors
Test Contents
My code:
"""File: guesswithgui.pyProject 8.5The computer guesses a number and the user provides thehints."""# imports the random moduleimport random# imports the breezypythongui modulefrom breezypythongui import EasyFrame
class GuessingGame(EasyFrame): """Plays a guessing game with the user.""" def __init__(self): """Sets up thewindow,widgets and data.""" EasyFrame.__init__(self,title = "Guessing Game") # sets the lowerBoundvalue self.lowerBound =1; # sets the upperBoundvalue self.upperBound =100; # sets the countvalue self.count = 0; # computes the initalvalue of myNumber self.myNumber =(self.lowerBound + self.upperBound) // 2; # Initial guess value isstored as a string guess = "Is the number "+ str(self.myNumber) + "?"; # adds the guess stringto a label self.myLabel =self.addLabel(text = guess, row = 0, column = 0, sticky = "NSEW",columnspan = 4); # adds a button 'Toosmall'. On button-click goLarge() is called self.small =self.addButton(text = "Too small", row = 1, column = 0, command =self.goLarge); # adds a button 'TooLarge'. On button-click goSmall() is called self.large =self.addButton(text = "Too large", row = 1, column = 1, command =self.goSmall); # adds a button'Correct'. On button-click goCorrect() is called self.correct =self.addButton(text = "Correct", row = 1, column = 2, command =self.goCorrect); # adds a button 'NewGame'. On button-click goNewGame() is called self.newGame =self.addButton(text = "New Game", row = 1, column = 3, command =self.goNewGame); # goLarge() def goLarge(self): # sets the countvalue self.count += 1; # changes the lowerboundvalue self.lowerBound =self.myNumber + 1; # updates the myNumbervalue with the updated lowerBound value self.myNumber =(self.lowerBound + self.upperBound) // 2; # changes the string inmyLabel self.myLabel["text"] ="Is the number " + str(self.myNumber) + "?"; # goSmall() def goSmall(self): # sets the countvalue self.count += 1; # changes the upperboundvalue self.upperBound =self.myNumber - 1; # updates the myNumbervalue with the updated upperBound value self.myNumber =(self.lowerBound + self.upperBound) // 2; # changes the string inmyLabel self.myLabel["text"] ="Is the number " + str(self.myNumber) + "?"; # goCorrect() def goCorrect(self): # disables the 'Toolarge' button self.large["state"] ="disabled"; # disables the 'Toosmall' button self.small["state"] ="disabled"; # disables the 'Correct'button self.correct["state"] ="disabled"; # goNewGame() def goNewGame(self): # enables the 'Toolarge' button self.large["state"] ="normal"; # enables the 'Toosmall' button self.small["state"] ="normal"; # enables the 'Correct'button self.correct["state"] ="normal"; # sets the initial valueof lowerBound self.lowerBound =1; # sets the initial valueof upperBound self.upperBound =100; # sets the initial valueof count self.count = 0; # computes the initalvalue of myNumber self.myNumber =(self.lowerBound + self.upperBound) // 2; # value in myLabel ischanged self.myLabel["text"] ="Is the number " + str(self.myNumber) + "?";def main(): """Instantiate and pop up the window.""" GuessingGame().mainloop()
if __name__ == "__main__": try: while True: main() except KeyboardInterrupt: print("\nProgramclosed.")
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply