Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I want to make a quiz. Plz help.

+1 vote
asked Apr 3, 2019 by Paolo Nader (280 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,'%')

2 Answers

+2 votes
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 (280 points)
The "better" is just a joke. Thanks:)
0 votes
answered Jun 13, 2021 by ITSME (740 points)
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
print ("What is",whi,"+",man,"?\n")# I had changed the output to another line
pie=int(input())  # If you are getting an integer input use this syntax
if pie==qua:
    print("Good")
    q+=1
else:
    print('Wrong')
toe=input("What is 9-6?") #Here no need to add the above syntax as you are checking the answer with a string
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,'%')
commented Jun 13, 2021 by ITSME (740 points)
I have corrected the mistakes for you and added some comments for better understanding
mainly some data based mistakes only can be rectified :)
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.
...