Python Forum

Full Version: my simple code wont work! help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

UPDATE - I fixed it - I had to force the input typo be an integer for the comparison

I am trying to make a multiplication tester program for school. I had the following code working at one stage, but after I tried to make some edits to loop its operation, it stopped evaluating the answers properly. I parsed it back to the original but it won't work and it id driving me crazy!

This is the code - it ALWAYS says "wrong answer" - I know my multiplication isn't THAT bad - help!

from tkinter import *
import tkinter as ttk
import random
from random import randrange

x = randrange(0,10)
y = randrange(0,10)

print("what is ",x," multiplied by ",y)

user_answer = input(": ")

answer = x*y

if user_answer == answer:
    print("Correct!!!!")
else:
    print("Wrong answer bruh...")
Simon
on input, you need to convert string to integer:

from tkinter import *
import tkinter as ttk
import random
from random import randrange
 
x = randrange(0,10)
y = randrange(0,10)
 
print("what is ",x," multiplied by ",y)

# better:
# print(f"what is {x} multiplied by {y}?")
 
user_answer = int(input(": "))

answer = x*y
 
if user_answer == answer:
    print("Correct!!!!")
else:
    print("Wrong answer bruh...")
import random

x, y = random.randrange(0, 10), random.randrange(0, 10)

if int(input(f"what is {x} times {y}\n")) == x*y:
    print("Correct!!!!")
else:
    print("Wrong answer")