Python - making my code more economic
Question: I need some help on making this code more economical - I am sure that, there
are a lot of lines I can cut down on.

The code is about a quiz that will ask 10 questions and your score will be
outputted at the end.

    
    
    import random
    studentname=input("what is your name?:")
    score=0
    trueanswer=0
    
    def question():
        global operation
        global number1
        global number2
        global studentanswer
        global score
        number1=random.randrange(1,10)
        number2=random.randrange(1,10)
        operation=random.choice(["*","-","+"])
        print("what is", number1,operation,number2,"?:")
        studentanswer=int(input("insert answer:"))
    
    def checking():
        global score
        if operation == "*":
            trueanswer = number1*number2
            if studentanswer == trueanswer:
                print("correct")
                score=score+1
            else:
                print("incorrect")
                score=score
        elif operation == "-":
            trueanswer = number1-number2
            if studentanswer == trueanswer:
                print("correct")
                score=score+1
            else:
                print("incorrect")
                score=score
        elif operation == "+":
            trueanswer = number1+number2
            if studentanswer == trueanswer:
                print("correct")
                score = score+1
            else:
               print("incorrect")
               score=score
    
    def main():
        for i in range (10):
            question()
            checking()
        print("your score is", score)
    
    main()
    


Answer: You can reduce the entire checking function to this:

    
    
    def checking():
        trueanswer = eval(str(number1)+operation+str(number2))
        if studentanswer == trueanswer:
            print("correct")
            score=score+1
        else:
            print("incorrect")
            score=score
    

