1.Same program as addition teaching program
2.But the student must get three questions correctly in a row to pass the test.
3.If the student get 1 question wrong, the counter will be reset to zero.
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 to pass the test.")
print("If you failed, you need to repeat the test.")
# setup the stop conditions for the program
# generate 5 addition questions
# before that, generate 2 numbers randomly
# compute the summation of the 2 numbers and store it in a variable
# Track how many questions were answered correctly by the student
# if the student got 3 questions and above correctly,
# congratulate the student and stop the program
# else, repeat the test.
import random
print("Welcome to New Academy:")
print("It is a mathematic test.")
print("You need to answer 3 questions correctly in a raw to pass the test.")
print()
correct = 0
while correct < 3:
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')
correct = 0
print('Congratulation!')
print('You have passed the test')
Comments
Leave a comment