Sorry im kinda new at this but anyways...

Ok heres the deal i need to make this program that will allow users to practice their addition and subtraction for whole numbers between 1 and 100, 1 and 200 and 1 and 500 (the levels of difficulty). The user will be allowed to choose which operation to have questions on and a series of 10 random questions will then be displayed. A message detailing whether they are correct or not will be displayed when it is checked. It's required to be in GUI and interactive...this is intended for primary school students i.e. Years 5 and 6...

I also need some help with splash screens in python that the program will open with a splash screen which will highlight: 1) the program title 2) who the program is for (3) who designed the program and, 4) what version of the program it is then it will cut to the main menu where the options will be (above paragraph)...

any help will be greatly apprieciated... :)

----------------------------------------------------------------------------------------------------------

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":
    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
if operation == "S" or operation == "s":
    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

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

    # Difficulty - Easy, Medium or Hard
    if difficulty == "Easy" or difficulty == "easy" or difficulty == "E" or difficulty == "e":
        number1 = random.randrange(100) + 1
        number2 = random.randrange(100) + 1
        
    if difficulty == "Medium" or difficulty == "medium" or difficulty == "M" or difficulty == "m":
        number3 = random.randrange(200) + 1
        number4 = random.randrange(200) + 1
        
    if difficulty == "Hard" or difficulty == "hard" or difficulty == "H" or difficulty == "h":
        number5 = random.randrange(500) + 1
        number6 = random.randrange(500) + 1

    # Addition Calculations
    if operation == "A" or operation == "a":
            if difficulty == "Easy" or difficulty == "easy" or difficulty == "E" or difficulty == "e":
                print number1, "+", number2, "="
            else:
                if difficulty == "Medium" or difficulty == "medium" or difficulty == "M" or difficulty == "m":
                    print number3, "+", number4, "="
                else:       
                    if difficulty == "Hard" or difficulty == "hard" or difficulty == "H" or difficulty == "h":
                        print number5, "+", number6, "="
        
    # Substraction Calculations
    if operation == "S" or operation == "s":
            if difficulty == "Easy" or difficulty == "easy" or difficulty == "E" or difficulty == "e":
                print number1, "-", number2, "="
            else:                 
                if difficulty == "Medium" or difficulty == "medium" or difficulty == "M" or difficulty == "m":
                    print number3, "-", number4, "="
                else:
                    if difficulty == "Hard" or difficulty == "hard" or difficulty == "H" or difficulty == "h":
                        print number5, "-", number6, "="

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

    # If Its "Correct" or "Incorrect"
    if (answer == number1+number2) or (answer == number3+number4) or (answer == number5+number6) or (answer == number1-number2) or (answer == number3-number4) or (answer == number5-number6):
        print "Correct :)"
        print
    else:
        print "Incorrect :("
        print

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

----------------------------------------------------------------------------------------------------------

NOTE - problem with the incorrect - it seems it doesn't work

Here are a few modifications I made:

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.")

The major thing that I did was clean up all the unnecessary if statements. Also, make sure you realize that there is an elif (else-if) statement, which I have added to your if structures.

By only needing to check the different possibilities once, and then setting your own variable to a known value (ie, my_op and my_rand_range), you can clean up your code a tremendous amount.

The other thing was that instead of having four if a == x statements, you can use the if a in [x] statement. Where [x] is a list of elements. Python knows that the 'in' keyword means, search each element in this list until you get a match. If a match is found the statement is resolved to a True, otherwise False.

A few things to consider further. If an incorrect difficulty or operation is input, how would you handle it? As your code stands it would crash. You should work in some error handling first to make sure that the user is playing 'nice'.

Try googling Python's try, except concepts to see how you could add in some elaborate error handling. For example, if instead of a number the user entered letters for an answer. The program would throw a ValueError exception, so you could wrap the answer = raw_input() statement with a try:, except 'ValueError': statement that would warn the user that only numerical answers are allowed, and then you could subtract one from the count so that they can't bypass a turn by putting in invalid answers.

Further more, without having an else: on your operation and difficulty if statements, you are inviting the user to crash your program. If they typed in 'R' for an operation just to be a brat your program would never ask for or assign any value to the difficulty parameter. As soon as your loop begins your program would crash with a NameError exception complaining that 'difficulty' is not defined.

On the other hand if they input bogus values for difficulty the rand_range would never be able to be determined and the program would again crash.

I think that you would benefit from implementing this game in wxPython.

By doing this, you can come up with a nice, clean interface to work with and you can very easily implement a splash screen as well.

I think that you would benefit from implementing this game in wxPython.

By doing this, you can come up with a nice, clean interface to work with and you can very easily implement a splash screen as well.

hey man thanks for the help and clean up of my code...works great...

um i dont think we can attemp this in wxPython...we are just using normal python...but im building the layout in Fireworks MX and then implementing it to python some how and make it interactive...ive attached my layout for the main menu screen if you wanna have a look...

if you can help me on that if not...then can you give me a run down on wxPython

Attachments Main_Menu.png 171.46 KB

That interface looks very nice!

wxPython is something that will allow you to make stand-alone programs, however it would be pretty difficult to come up with an interface as kid-friendly or inviting as the one that you've already created there.

I've unfortunately never used Fireworks, however I'd be glad to help in any way possible (as I'm sure the rest of this community of experts would). So don't be shy about asking for more help!

That interface looks very nice!

wxPython is something that will allow you to make stand-alone programs, however it would be pretty difficult to come up with an interface as kid-friendly or inviting as the one that you've already created there.

I've unfortunately never used Fireworks, however I'd be glad to help in any way possible (as I'm sure the rest of this community of experts would). So don't be shy about asking for more help!

oh ok cool thanks man

But just to make you sure I actually havn't implemented to function with python yet thats what i need help on but they is generally a layout i did in fireworks of what it would look like...fireworks basically enables web designers to produce high quality images and editing as well like Photoshop.

I need more help indeed. lol...um well at the end of questions i want it show a "Certificate" that will be displayed showing:
a) the level chosen (easy, medium and hard)
b) the type of operation that was tested (Addition and Substraction)
c) the percentage they got correct (If they score 9 out of 10 then the percentage is 90%)
d) a comment (e.g. Needs Improvement)

if you can help me with that, that will be awesome as well...

thanks man

This article has been dead for over six months. Start a new discussion instead.