python - Random function selecting -
A strange problem with my code 14 times asking questions, I should ask only 10 questions. Then it is not calculating the score correctly. Any help to fix these two problems is appreciated! In advance thank you
random studentname = import input ("Please enter the name:") def question_a (): score = 0 points1 = random.rendant (1,10) num2 = random Randint (1,10) num3 = num1-num2 answer = int ("what is + str (num1) +" - "+ str (num2) +"? "))) If answer == num3: print ( "Well score (score): score = 1 point = 1 = random.randint (1,10) num2 = random.randint (Score: 5, Average rating) 1,10) num3 = num1 + num2 answers = (What is "+ str (num1) +" + "+ str (num2) +"? ")) Answer == num3: score = score + 1 print (" Ok, you are right ") and: Print ( "This is a wrong answer") Turn score DEF question_c (): score = 0 number1 = random.Rendent (1,10) num2 = random.randint (1, 10) num3 = num1 * num2 answer = int (input "(" what is + str (num1 ) "Reply" == num3: score = score + 1 print ("Well done, you are right") and: print ("This is a wrong answer" + "+ str + +" + str (num2) + "?")) ) Return score def_Q (): score = 0 num1 = random.randint (1,10) num2 = random.randint (1, 10) Num3 = num1 / num2 num4 = round (num3,1) answer = float (input (" What is "+ str (num1) +" / "+ str (num2) +"? ")) Answer == num4: score = score + 1 print (" Well done, you are right "): Print (" This is a wrong answer ") Return score my_list = [question_a, question_b, question_c, question_d] Category (0,10): Random keys. (My_list) () final_score = (question_a () + question_b () + question_c () + question_d () print (student name + ", you have" + str (last_core) + "/ 10. ")
This line:
Random.choice (my_list) () 10 random work calls: correct.But ignoring the output: incorrect.
Then this row:
final_score = (question_a () + question_b () + question_c () + question_d ()) calls these tasks randomly and adds results 10 + 4 is equal to 14 calls in your work.
Solution: (<0>) for category i (0,10) final_score = 0: last_core + = Random keys. (My_list) ()
Or something like that.
Comments
Post a Comment