Reputation: 1
import random
def mathquiz():
name = str(input("Whats your name?:"))
a = random.randint(1,10)
b = random.randint(1,10)
c = (a * b)
timesby = ("*")
print('what is', + a, timesby, + b)
ans = input("Enter your answer here")
if ans == c:
print("Thats correct")
else:
print ("Incorrect the answer is", + c)
I am trying to create a maths quiz using random numbers and just say the question is 10 * 10 if i enter 100 if will say i have the wrong answer. Everything else works fine just this bit is wrong.
Upvotes: 0
Views: 105
Reputation: 146
ans and c are of different types. Since you read ans from the console, it is a string, and not a number, while c is calculated through multiplying 2 numbers, so it is a number. there are 2 ways to fix this, convert ans to an int with int(ans) instead of ans, or convert c to a string with str(c) instead of c.
Upvotes: 2