I want to make a quiz. Plz help.

+1 vote
asked Apr 3, 2019 by Paolo Nader (260 points)
edited Apr 3, 2019 by Paolo Nader

I want to make a math machine that will randomly get two numbers, add them together, then answer the question, then ask the person the question. It doesn't work. Plz help. The bold part is the part that goes wrong. Here is the code:

q=0
print("Welcome to this math test.")
print('Here is your first question.')
from random import *
 
man = randint(1, 100)
from random import *
 
whi = randint(1, 100)
qua=whi+man
pie=input("What is ",whi,"+",man,"?")
if pie==qua:
    print("Good")
    q+=1
else:
    print('Wrong')
toe=input("What is 9-6?")
if toe=='3':
    print('Better')
    q+=1
else:
    print("Wrong")
fed=input('What is 12x11?')
if fed=='132':
    print('Fantastical')
    q+=1
else:
    print("Wrong")
print("Here is your score")
result=q*33
print(result,'%')

1 Answer

+1 vote
answered Apr 3, 2019 by Frankje
selected Apr 4, 2019 by Paolo Nader
 
Best answer

Two things have to be changed:

1. When using input(), you have to give only one argument, not 5. So you have to join the different parts of your question into one string. This is done via +, but all Arguments should be strings, so the correct line is

pie=input("What is "+str(whi)+"+"+str(man)+"?")

2. The return value of input() is a string, but qua is an integer. Convert it to a string so the two can be compared:

if pie==str(qua):

One thing I couldn't help noticing: if the second answer is correct, the answer is "Better", irrespective of whether you got the first one right. Maybe this should be changed …

Hope this helps!

commented Apr 4, 2019 by Paolo Nader (260 points)
The "better" is just a joke. Thanks:)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...