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.")
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()
Comments
Leave a comment