I've been trying to create a programme that generates equation based questions to which you give an answer and it marks it by providing a popup messagebox. I've got it to the point where it all works, which I can tell as I've got print commands that give the answer, but it always marks it as incorrect, no matter what the answer you provide is.
These are the bits of code that are important:
global uAnswer
uAnswer = tk.Entry(questionsWindow, width= 30)
#uAnswer.insert(0, "Enter answer to 2 decimal places.")
uAnswer.pack()
calculateButton2 = tk.Button(questionsWindow, text = "Mark Answer", command = calculateV2)
calculateButton2.pack()
and:
def calculateV2():
try:
if (buttonId == 1):
intAnswer=uAnswer.get()
r = int(cNum[1].cget("text"))
print (r)
V = (4/3)*(math.pi)*(r**3)
V = round(V, 2)
print (V)
print (intAnswer)
print (buttonId)
if (V == intAnswer):
messagebox.showinfo("Answer", "Correct Answer")
else:
messagebox.showinfo("Answer", "Incorrect Answer")
Just in case you need to know, the value of buttonId in this case is definitely 1 and the value of r is always a whole number between 1 and 9. I've been trying for ages and just can't figure out why it's not working. Thanks for any help.
Aucun commentaire:
Enregistrer un commentaire