How to convert '*' to *
Question: I am making a math quiz game in python, where the computer selects 2 numbers
and 1 symbol from a list and prints it, then the user answers the question. In
my list with the symbols, I have the math symbols as strings, but when I want
the computer to get the answer, It can't, because the symbols are strings. How
do I convert the '*' string to the * symbol used in math? Any help is
appreciated, I will post what I have of the game so far as well.

    
    
    import random
    import time
    import math
    
    symbols = ('*', '+', '-', '/')
    count = 0
    def intro():
        print("Hi")
        print("Welcome to the math quiz game, where you will be tested on addition")
        print("Subtraction, multiplication, and division, and other math skills")
        time.sleep(3)
        print("Lets begin")
    
    def main(count):
            number_1 = random.randrange(10,20+1)
            number_2 = random.randrange(1,10+1)
            symbol = (random.choice(symbols))
            print("Your question is: What is %d %s %d") %(number_1, symbol, number_2)
    
    
    main(count)
    


Answer: You have to give a meaning to those symbols. One way would be by realizing
that each of these symbols is a function that takes two arguments. Thus you
can do:

    
    
    symbols = {
        '*': lambda x, y: x*y,
        '+': lambda x, y: x+y,
        '-': lambda x, y: x-y,
        '/': lambda x, y: x/y,
    }
    

and then you can do

    
    
    number_1 = random.randrange(10,20+1)
    number_2 = random.randrange(1,10+1)
    symbol = random.choice(symbols.keys())
    operator = symbols[symbol]
    result = operator(number_1, number_2)
    

