Python Forum
my simple code wont work! help!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my simple code wont work! help!
#1
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
Larz60+ write Sep-05-2021, 03:27 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply
#2
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...")
simon12323121 likes this post
Reply
#3
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")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  First Day using Python. NEED Simple Math CODE HELP! Jesseluke 4 1,373 Jan-13-2023, 01:04 PM
Last Post: jefsummers
  My code does not work as expected (pygame) rohes_kaugummi 1 1,574 Aug-26-2021, 03:13 PM
Last Post: deanhystad
  I wrote a code but it does not work out as expected chinitayao226 2 1,871 Sep-23-2020, 09:14 PM
Last Post: SnowwyWolf
  Why wont this work? samh625 6 3,337 Jul-30-2020, 08:30 PM
Last Post: perfringo
  A program for backing up documents (doesnt work(code is inside)) Richard_SS 4 3,419 Jun-05-2019, 03:47 PM
Last Post: heiner55
  MyProgrammingLab wont accept anything I put in chicks4 2 11,577 Feb-10-2019, 11:44 PM
Last Post: chicks4
  I Can't Get This Sorting Function In This LinkedList Code To Work JayJayOi 10 7,929 Jan-11-2018, 01:14 AM
Last Post: JayJayOi
  Can anyone please help with very simple code bee 6 4,891 Sep-29-2017, 02:26 PM
Last Post: ichabod801
  Need help with getting this voting eligiblity code to work Beastly 1 2,525 Aug-16-2017, 03:46 PM
Last Post: ichabod801
  Why can't this code work. sexualpanda 2 3,421 Feb-06-2017, 04:03 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020