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=0print("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+manpie=input("What is ",whi,"+",man,"?")if pie==qua: print("Good") q+=1else: print('Wrong')toe=input("What is 9-6?")if toe=='3': print('Better') q+=1else: print("Wrong")fed=input('What is 12x11?')if fed=='132': print('Fantastical') q+=1else: print("Wrong")print("Here is your score")result=q*33print(result,'%')
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:
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!