samedi 10 septembre 2016

Simple Guessing Game not working

This is supposed to be a guessing game. If the user submits a number that is higher than the pre-set value (which is 10), it will say go lower. And if the user submits a lower number, it will say go higher. The problem I'm facing is that it only tells me to go higher with every integer or even string I type in. Any clue what the problem might be?

Also, the reason I turned 10 into a string is because it gives me an error if it's an integer.

from tkinter import *

# Simple guessing game
window = Tk()

def number():
    if typed == key:
        print("This is the correct key")
    elif typed > key:
        print("Go lower!")
    else:
        print("Go higher!")

e = Entry(window)
e.pack()

key = str(10)
typed = e.get()

b = Button(window, text="Submit", command=number)
b.pack()

window.mainloop()

Aucun commentaire:

Enregistrer un commentaire