hey

well this program basically is a mathematics game...try the program out for yourself, it works, but im just wondering how to make an reset option so at the end of the program so the user can play the game again.

thanks

name = raw_input("\t\t\tPlease Enter Your Name: ")

print
print "\t\t\t\tHello", name
print "\t\t\tWelcome to my Mathematics Game"

# Selecting the operation of Addition and Substraction followed by the difficulty
print
operation = str(raw_input("\t\t\tAddition (A) or Substraction (S)"))
if operation == "A" or operation == "a":
    my_op = 'Add'
    difficulty = str(raw_input("\tSelect a difficulty - Easy (E)(1-100), Medium (M) (1-200) or Hard (H) (1-500)"))
    print
    print "Addition"
    print '** ** **'
    print
elif operation == "S" or operation == "s":
    my_op = 'Sub'
    difficulty = str(raw_input("\tSelect a difficulty - Easy (E)(1-100), Medium (M) (1-200) or Hard (H) (1-500)"))
    print
    print "Subtraction"
    print '** ** ** **'
    print

if difficulty == "Easy" or difficulty == "easy" or difficulty == "E" or difficulty == "e":
    my_rand_range = 100
elif difficulty == "Medium" or difficulty == "medium" or difficulty == "M" or difficulty == "m":
    my_rand_range = 200
elif difficulty == "Hard" or difficulty == "hard" or difficulty == "H" or difficulty == "h":
    my_rand_range = 500

# Amount of questions asked (10) and randomisation of numbers
import random
counter = 0
while counter < 10:
    counter = counter +1

    # Difficulty - Easy, Medium or Hard
    number1 = random.randrange( my_rand_range ) + 1
    number2 = random.randrange( my_rand_range ) + 1

    # Addition Calculations
    if my_op == 'Add':
        print number1, "+", number2, "="
    # Substraction Calculations
    elif my_op == 'Sub':
        print number1, "-", number2, "="

    # Input for answer
    answer = int(raw_input("Type in your answer: "))

    # If Its "Correct" or "Incorrect"
    if ( answer == number1 + number2 and my_op == 'Add' ) or \
        ( answer == number1 - number2 and my_op == 'Sub' ):
        print "Correct :)"
        print
    else:
        print "Incorrect :("
        print

raw_input("\n\nPress the enter key to exit.")

What you should do is rewrite your program and put it on a while loop so that when it ends it restarts by itself. Once you got that you should make a quit option and the program should work properly. Thus, your program will restart every time it ends and there will be an option to quit so they can stop the program. Here is an example of one of my programs look at the end of the program that’s where the while loop is located. Hopefully this helped you and good luck.

link:

http://www.daniweb.com/code/snippet887.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.