'Python Menu option only works once

I'm new to Python and have been experimenting. I've created a simple program with a menu so my grandson can practice his multiplication tables.

I run the script and a menu appears. Menu option allows a multiplication table quiz to be launched.

Each menu option executes a function which imports the relevant script, runs through asking the questions and keeps score. If all questions are answered an appropiate message is printed and if not, another message is printed.

Now the issue I'm facing is that if say for example the two times table is selected, it works on the first run but when the same option is selected again to 'retake' the quiz, it doesn't launch the script. It just executes the print statement.

Having researched online etc, the import only works once. Is there a way of reloading the function so the script i.e two times table runs again??

I've included some code below:

def onetimes(): import one_timestable...etc

menu = {}
menu['1']= "One Timestable"
menu['2']= "Two Timestable"
menu['3']= "Three Timestable"
menu['4']= "Four Timestable".......etc

while True:
    options=menu.keys()
    for entry in options:
        print (entry, menu[entry])
        print()
    selection=input("Please choose your quiz:")
    if selection =='1':
        print("You've chosen the one timestable quiz")
        print()
        onetimes()
    elif selection == '2':
        print("You've chosen the two timestable quiz")
        print()
        twotimes()
    elif selection == '3':
        print("You've chosen the three timestable quiz")
        print()
        threetimes()....etc

Any pointers would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source