Q:

Capture value from function

I'm having trouble while trying to store the output of the function below, basically I'm trying to create a maths quiz which asks randomized basic math questions and then gives the ability to answer those questions while checking whether they are correct and was wondering if anyone was able to help me out with the code or provide me insight into what I need to learn in order to complete it.
Here is what I have so far:
print ("Hello to the maths quiz, what is your name?")
name = input()
from random import choice,randint

def rand_task1mathquiz():
    a,b = randint(0,10),randint(0,10)
    random_operations = choice(["+","-","/","*"])
    print("{0} {1} {2}".format(a,random_operations,b))

if __name__ == "__main__":
    for x in range(10):
    rand_task1mathquiz()

A:

The general pattern you are looking for is the return statement.  When you want to capture the return value of a function, typically, you'd assign the function's result to a variable, just as you assign static values to variables, except for the () on the right-hand side which makes it into a function call to be evaluted, rather than a reference to the function object.
Notice also how you were already doing this with the return values from the library functions randint(), choice(), range(), etc.
def rand_task1mathquiz():
    a,b = randint(0,10),randint(0,10)
    random_operations = choice(["+","-","/","*"])
    return("{0} {1} {2}".format(a,random_operations,b))

if __name__ == "__main__":
    for x in range(10):
        quiz = rand_task1mathquiz()
        print quiz
        # Probably evaluate the returned value somehow, compare to user input

The changed division of labor here is also worth noting -- the function returns a value, and the caller prints it.  A useful function can run on its own, with no user interaction; input/output functionality should be kept separate from program logic as far as possible.
If you want to create a list of questions, that's easy now, too:
questions = list()
for x in range(10):
   questions.append(rand_task1mathquiz())
# Now do something with questions

or equivalently, but somewhat less readably, using a list comprehension:
questions = [rand_task1mathquiz() for _ in range(10)]

A further improvement might be to have the function return both the question and the answer; it makes sense to keep them both close together in the program code.
def rand_task():
    a,b = randint(0,10), randint(0, 10)
    ops = {'+': int.__add__, '-': int.__sub__,
        '/': int.__truediv__, '*': int.__mul__}
    random_operation = choice(list(ops.keys()))
    # Should still guard against op='/' with b==0
    return ops[random_operation](a, b), \
        '{0} {1} {2}'.format(a, random_operation, b)

... though using __add__ and friends is probably too tricky to properly understand just yet.  It certainly beats eval in terms of security, so perhaps you should try it.

