I created a number guessing game. However, I keep on running into an error.
The problem is when I run it and enter the number it will eventually say the number is higher than 74 (this is an example) but lower than 75... If I set a specific number it works fine, but when I generate a random number it doesn't work.
import random
from tkinter import *
def checkInput():
randomNumber = random.randint(1,100)
user_guess = int(user_input.get())
if user_guess == randomNumber:
print("You got it!")
if user_guess > randomNumber:
print("Guess lower!")
if user_guess < randomNumber:
print("Guess higher!")
root = Tk()
user_input = Entry(root)
user_input.pack()
check_button = Button(root,text="Check",command=checkInput) .pack()
reset_button = Button(root,text="Reset") .pack()
root.mainloop
mainloop? You generate a new random number on each go. So you are guessing a moving target. You should generate the number at the start and compare all subsequent guesses to that number.checkInputso previous indications do not apply....