Python please tell me if my maths answer is right
Question: I wish to add a feature which tells the user when he/she has answered
correctly to the random maths questions that are given.

    
    
    import random
    
    def answers():
        correct_answer_P_ = ((str(difficulty_one + difficulty_one))) #P = PLUS, ADDITION +  
    
        correct_answer_M_ = ((str(difficulty_one * difficulty_one))) #M = MULTIPLY *
    
        correct_answer_T_ = ((str(difficulty_one - difficulty_one))) #T = TAKE AWAY, MINUS -
    
    def random_symbols():
        symbols = random.choice (["+","-","*"])
        return symbols
    
    def difficulty_one():
        dif_one = random.randrange (1,10,1)
        return dif_one
    
    def questions():
        question = (str(difficulty_one())) + random_symbols() + (str(difficulty_one())) + " = "
        return question
    
    
    start = input("press start to begin!: ")
    
    
    if (start == "start"):
        print ("here's ten questions, good luck!")
        for questions_num in range(1,11):
            print ("Question ",questions_num)
            input(questions())
            if (random_symbols == "+"):
                if (dif_one == correct_answer_P_):
                                print("correct!")
    
            elif(random_symbols == "-"):
                if (dif_one == correct_answer_T_):
                                print("correct!")
    
            elif(random_symbols == "*"):
                if (dif_one == correct_answer_M_):
                                print("correct!")
            else:
                print("incorrect!")
    

I tried this from getting some advice from a friend who said that i needed to
create variables for each symbol that would be randomly inserted; the
variables should compare the users answer and say its correct but it skips all
the if statements and goes straight to saying its incorrect.

Any suggestions? Don't be harsh if I'm doing something dumb because I've just
started python at the moment.

Quick note the part in this code has been cut out of my original to make it
simple for people to see what I'm trying to do.


Answer: There's a way easier way of implementing this. Try this instead:

    
    
    import operator
    
    questions = [(1,2), (4,2), (8,1), (10,100)] # operands for your questions
    operators = {"+" : operator.add,
                 "-" : operator.sub,
                 "*" : operator.mul}
    # a dictionary containing each operator's symbol and the resulting function
    # (operator.add(x,y) is equivalent to x+y)
    
    for num, operands in enumerate(questions,start=1):
        # iterate through each set of operands, enumerating starting at 1 
        operator = random.choice(operators)
        # return a random symbol from operators
        answer = operators[operator](*operands)
        # operators[operator] is the function, which we then call with the operands
        q_text = "{} {} {} = ?".format(str(operands[0]), operator, str(operands[1]))
        print("Question {}".format(str(num)))
        print(q_text)
        user_answer = input(">>")
        if float(user_answer) == answer:
            # correct!
        else:
            # fail!
    

