Description Guess the number game: The player's task is to guess which number the computer has in the fewest possible moves. The computer has a random number between 1 and 1000. For each round, the...

1 answer below »
python


Description Guess the number game: The player's task is to guess which number the computer has in the fewest possible moves. The computer has a random number between 1 and 1000. For each round, the user must enter a number in the text field and press the "guess number" button. The program should then print in a Label if the user's number is greater than or less than the number the program has, and if it is closer or further away from the number than the previous number the user guessed. The program should also print out how many rounds the player has used so far. Tasks a) Create a class that draws the graphical user interface, which can look like the picture. b) Create a method in the GUI class that reads the text from a text field and converts it to an integer if possible. c) Create a method in the GUI class to be executed when the user presses the button. The method shall use the method from problem b). If what the user typed can be converted to an integer, the code should check the number the user typed against the number in the system and write the correct message to the message field. If what the user wrote cannot be converted to an integer, the user should get an error message. d) When the user enters the correct number (the number the computer has made and which the user should guess) the program should show a dialog "You have guessed correctly!" which also says how many attempts the user used. e) Enter code in the constructor of the GUI class that creates a random number between 1 and 1000, sets up the game, adds listeners if needed, so that the program works as described in the "description" section.
Answered 1 days AfterMar 27, 2021

Answer To: Description Guess the number game: The player's task is to guess which number the computer has in...

Aditya answered on Mar 29 2021
135 Votes
import random
from tkinter import *
from tkinter import messagebox
class GUI:
def __init__(s
elf):
self.random_number = int(random.uniform(1,1000))
self.attemp = 0
def readNumber(self):
try:
n = int(self.number.get())
self.attemp = self.attemp + 1
if n == self.random_number:
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here