Python Math Game Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TurtleGuy910
    New Member
    • Aug 2007
    • 16

    #1

    Python Math Game Error

    I made a math game and wanted it to print out which questions you got right at the end. How do i do that? This is my code.

    # Welcome To The Math Game
    print "Welcome To The Math Game."
    print "------------------------"
    #Rules
    print
    print "Just answer the problems as well as you can and do not use a calculator."
    print "At the end you will get your score."
    print "You will be asked 4 problems one multiplication one adding one subtracting and one dividing."
    print "Lets Start."
    print
    # Start It
    answer0 = 0
    if answer0 == 0:
    answersright = 0
    else:
    blah = 0
    # Problem1
    print "34*32"
    answer1 = input()
    if answer1 == 1088:
    answersright=an swersright+1
    else:
    answersright=an swersright
    #problem 2
    print "234/13"
    answer2 = input()
    if answer2 == 18:
    answersright = answersright+1
    else:
    answersright=an swersright
    #problem 3
    print "412+2345"
    answer3 = input()
    if answer3 == 2768:
    answersright = answersright+1
    else:
    answersright=an swersright
    #problem 4
    print "234-2548"
    answer4 = input()
    if answer4 == -2314:
    answersright=an swersright+1
    else:
    answersright=an swersright
    #End Of Problems
    print "Congratulation s you just finished the math game"
    print "You will now receive your score"
    print "You Got..."
    from time import sleep
    sleep(3)
    if answersright == 0:
    print "0 right"
    else:
    bob = 1
    if answersright == 1:
    print"1 Right"
    else:
    blah = 1
    if answersright == 2:
    print "2 right"
    else:
    blah = 2
    if answersright == 3:
    print "3 right"
    else:
    blah = 3
    if answersright == 4:
    print "4 right"
    problem0 = 0
    else:
    blah2 = 1
  • Elias Alhanatis
    New Member
    • Aug 2007
    • 56

    #2
    Hello there!

    I think the first thing you should do is to get your program to work
    with a 'for' loop , so you wont have to write the same things amny times...
    Before that , you must prepare a 'list' of 'lists' with the question,the correct answer and a 'flag' reference , which your program will change according to wether the answer was wright or wrong. Then at the end , you can sum all the questions which have a "correct answer" flag , and print them.
    Here is a guideline:

    Code:
    question_list=[["10*10",100,0],["20*20",400,0]]
    for question in question_list:
         answer = raw_input "how much is "+question[0]+" ?"
         if answer==question[1]:
                question[2]=1
    This code modifies the third item of each sublist to "1" if the answer was correct , so all you have to do is check which sublists have "1" as third item.
    Hope i helped a little....

    Elias

    Comment

    • TurtleGuy910
      New Member
      • Aug 2007
      • 16

      #3
      Thanks for you help. I got it fixed with the following code:

      # Welcome To The Math Game
      print "Welcome To The Math Game."
      print "------------------------"
      #Rules
      print
      print "Just answer the problems as well as you can and do not use a calculator."
      print "At the end you will get your score."
      print "You will be asked 4 problems one multiplication one adding one subtracting and one dividing."
      print "Lets Start."
      print
      # Start It
      answer0 = 0
      if answer0 == 0:
      answersright = 0
      else:
      blah = 0
      # Problem1
      print "34*32"
      answer1 = input()
      if answer1 == 1088:
      answersright=an swersright+1
      q1=1
      else:
      answersright=an swersright
      q1=0
      #problem 2
      print "234/13"
      answer2 = input()
      if answer2 == 18:
      answersright = answersright+1
      q2=1
      else:
      answersright=an swersright
      q2=0
      #problem 3
      print "412+2345"
      answer3 = input()
      if answer3 == 2768:
      answersright = answersright+1
      q3=1
      else:
      answersright=an swersright
      q3=0
      #problem 4
      print "234-2548"
      answer4 = input()
      if answer4 == -2314:
      answersright=an swersright+1
      q4=1
      else:
      answersright=an swersright
      q4=0
      #End Of Problems
      print "Congratulation s you just finished the math game"
      print "You will now receive your score"
      print "You Got..."
      from time import sleep
      sleep(3)
      if answersright == 0:
      print "0 right"
      else:
      bob = 1
      if answersright == 1:
      print"1 Right"
      else:
      blah = 1
      if answersright == 2:
      print "2 right"
      else:
      blah = 2
      if answersright == 3:
      print "3 right"
      else:
      blah = 3
      if answersright == 4:
      print "4 right"
      problem0 = 0
      else:
      blah2 = 1
      if q1>0:
      print "You got question 1 right"
      else:
      print "You got question 1 wrong"
      if q2>0:
      print "You got question 2 right"
      else:
      print "You got question 2 wrong"
      if q3>0:
      print "You got question 3 right"
      else:
      print "You got question 3 wrong"
      if q4>0:
      print "You got question 4 right"
      else:
      print "You got question 4 wrong"

      Comment

      Working...