Looping and functions

python

#1

I am not good at coding and I am trying to change that but I am having troubles with this assignment. I have to create a math quiz where I ask the user to answer a simple addition question that uses two random integers. If they get the question right I am supposed to say congrats and ask them if they would like to answer another. If they get it wrong then the program needs to print the correct answer and again ask them if they would like to answer another until the user says no. Any suggestions would help immensely, thanks.

import random
from sys import exit
answer=str(a+b)
def loop(q):
q=input('Would you like to answer another question?')
if q == ("yes"):
return (question)
else:
print ("Goodbye")
exit

def rand(a,b):
a=random.randint(1,1000)
b=random.randint(1,1000)

def question(q,a,b,math):
math=raw_input("What is" (a + b)
if math == (answer):
return("congratulations")
else:
print("Sorry the correct answer is" (answer))


#2

Hello, @zachjosh1592!
You're adding a andd b, which have no value stored on it, into answer after converting them into strings, that's not correct.

Doing:

if q == ("yes"):
        return (question)

Isn't correct, you're calling a function which has four parameters (q, a, b, math) but you're not passing anything.
Your question function have the parameters I mencioned above and why would you pass "q" and "math" to it?
Remember: we only pass to functions things we will actually work with, otherwise there's no need.
So in your function loop() there's no need to have a parameter since it won't be really used for anything, in fact it's value that was passed will be overwritten when you prompt for the user to type something.
So what I think you can do:
At your first function, just call the other function question() other than return it's value if the user types "yes".
At the function if the user got it right just print "Congratulations!" or any other message you'd like and call the function loop(), in case he/she wants to do it again.
But if the got it wrong, just print the message on the screen and call the function loop() so he/she can have another chance.

Hope this helps you!
Quote or message me if there's anything else I can help you with!

Best regards,
g4be