Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Help update python Code below: Make user only have 5 tries to guess the Number print game over from tkinter import * import random class
Help update python Code below: Make user only have 5 tries to guess the Number print game over from tkinter import * import random class App: def __init__(self, master): frame = Frame(master) frame.pack() self.button = Button(frame, text="QUIT", fg="red", command=frame.quit) self.button.pack(side=LEFT) self.number = Button(frame, text="Guess Your Number", fg="green", command=self.number) self.number.pack(side=LEFT) def number(self): print ("hi there, everyone!") secret_number=0 secret_number=random.randint(1,100) guess=0 tries=0 while guess != secret_number: g=input("guess my number: ") if g == "Q": self.button = Button(frame, text="QUIT", fg="red", command=frame.quit) self.button.pack(side=LEFT) tries=tries+1 guess=int(g) if guess > secret_number: print("high") if guess < secret_number: print("low") if guess == secret_number: print("you win!!! the secret number is: ", secret_number) print("you took ", tries, "tries") print("game over") root = Tk() app = App(root) root.mainloop()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started