python - I really need help, this is my code below and i want to give a random comment for each correct answer -


import random score = int(0)  q1 = ("work out answer. 45 + 46 = ") q2 = ("kai buys pair of shoes £31 , shirt £67. altogether, spends £") q3 = ("work out answer. 68 - 29 = ") q4 = ("a bike costs £260. price reduced in sale £90. sale price of bike ") q5 = ("work out answer. 32 x 30 = ") q6 = ("a box holds 22 apples. total number of apples in 20 boxes ") q7 = ("work out answer. 70 x 7 = ") q8 = ("for school show, 22 chairs arranged equally in 30 rows. total number of chairs ") q9 = ("a function machine changes 49 98 , changes 26 '?'. number in question mark ") q10 = ("what number fills gap? 35 x ? = 105. number ") question = [ (q1, "91"), (q2, "98"), (q3, "39"), (q4, "170"), (q5, "960"), (q6, "440"), (q7, "490"), (q8, "660"), (q9, "52"), (q10, "3")  ]  comments = ["correct, 1 point, onto next question", "at least i'm not smart 1 around here", "well done", "you must smart", "some people have failed @ question",  "congratulations", "good work guess...", "you got right?!"]  random.shuffle(question) question, correctanswer in question: answer = input (question + "") if answer == correctanswer:     correcta = 1  random.shuffle(comments) if correcta == 1:     print(comments[random.randrange(len(comments))])     score = score + int(1)     print("your current score " + str(score)) else:     print("wrong, correct answer " + correctanswer)     score = score - int(1)     print("your current score " + str(score)) 

this updated version , there no syntax errors while fix of errors, 2 errors remain. 1) after user has inputted answer, nothing appears, not score prints. 2)the comment appears after every question has been answered. how fix both of these problems?

one way choose random element in sequence use choice function in random library.

import random = [1,2,3] random.choice(a) # chooses random element in list 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -