By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 443,923 Members | 1,655 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

# Python Math Game Error

 P: 16 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=answersright+1 else: answersright=answersright #problem 2 print "234/13" answer2 = input() if answer2 == 18: answersright = answersright+1 else: answersright=answersright #problem 3 print "412+2345" answer3 = input() if answer3 == 2768: answersright = answersright+1 else: answersright=answersright #problem 4 print "234-2548" answer4 = input() if answer4 == -2314: answersright=answersright+1 else: answersright=answersright #End Of Problems print "Congratulations 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 Nov 30 '07 #1
Share this Question
2 Replies

 P: 56 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: Expand|Select|Wrap|Line Numbers 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 Dec 2 '07 #2

 P: 16 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=answersright+1 q1=1 else: answersright=answersright q1=0 #problem 2 print "234/13" answer2 = input() if answer2 == 18: answersright = answersright+1 q2=1 else: answersright=answersright q2=0 #problem 3 print "412+2345" answer3 = input() if answer3 == 2768: answersright = answersright+1 q3=1 else: answersright=answersright q3=0 #problem 4 print "234-2548" answer4 = input() if answer4 == -2314: answersright=answersright+1 q4=1 else: answersright=answersright q4=0 #End Of Problems print "Congratulations 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" Dec 2 '07 #3

### Post your reply

Sign in to post your reply or Sign up for a free account.