Assignment pls heLP
b. Modify the GuessingGame2 program so that the player is criticized for making a “dumb” guess. For example, if the player guesses that the random number is 4 and is told that the guess is too low, and then the player subsequently makes a guess lower than 4, display a message that the user should have known not to make such a low guess. Save the ? le as GuessingGame3.gui.

Prasad RaveendranRank #320 · 7.8K reputationPosted Jun 13, 2024, 6:36 PM EDT
import random import tkinter as tk from tkinter import messagebox class GuessingGame: def __init__(self, master): self.master = master self.master.title("Guessing Game") self.random_number = random.randint(1, 100) self.previous_guess = None self.label = tk.Label(master, text="Guess the number between 1 and 100") self.label.pack() self.entry = tk.Entry(master) self.entry.pack() self.guess_button = tk.Button(master, text="Guess", command=self.check_guess) self.guess_button.pack() def check_guess(self): try: guess = int(self.entry.get()) except ValueError: messagebox.showwarning("Invalid input", "Please enter a valid number") return if self.previous_guess is not None: if guess self.random_number: messagebox.showinfo("Result", "Too high!") else: messagebox.showinfo("Result", "Congratulations! You guessed it!") self.previous_guess = guess self.entry.delete(0, tk.END) def main(): root = tk.Tk() game = GuessingGame(root) root.mainloop() if __name__ == "__main__": main()previous_guessvariable keeps track of the last guess made by the player.tkinterwith an input field for the player's guess and a button to submit the guess.Save the above code in a file named
GuessingGame3.guiand run it to play the game.