Answer to Question #310163 in Python for xxx

Question #310163

1.Create a program to test the addition (+) skill of students. (0 – 100)

2.The program can automatically generate 5 questions for a student to answer.

3.A student must correct at least 3 questions to pass the test. 

4.If the student failed, he needs to repeat the test.


Code:

import random


print("Welcome to New Academy:")

print("It is a mathematic test. You have to answer 5 questions.")

print("You need to answer 3 questions correctly in a row to pass the test.")


1
Expert's answer
2022-03-12T03:47:33-0500
import random


print("Welcome to New Academy:")
print("It is a mathematic test. You have to answer 5 questions.")
print("You need to answer 3 questions correctly in a row to pass the test.")
print()


testPass = False
while not testPass:
    correct = 0
    for i in range(5):
        x1 = random.randint(0, 100)
        x2 = random.randint(0, 100)
        print(f'What is {x1} plus {x2}? ', end='')
        ans = int(input())
        if ans == x1 + x2:
            print('Correct')
            correct += 1
        else:
            print('You are wrong')
    if correct >= 3:
        print('Congratulation!')
        print('You have passed the test')
        testPass = True
    else:
        print('You don\'t pass the test.')
        print('Try again.')
        print()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS