import time
import random
def arithmetic_test(num_questions):
score = 0
times = []
for i in range(num_questions):
num1 = random.randint(1, 1000)
num2 = random.randint(1, 1000)
operator = random.choice(['+', '-', '*', '/'])
question = f'Question {i+1}: {num1} {operator} {num2} = '
start_time = time.time()
answer = input(question)
end_time = time.time()
elapsed_time = end_time - start_time
times.append(elapsed_time)
try:
if float(answer) == eval(f'{num1}{operator}{num2}'):
print('Correct!')
score += 1
else:
print('Incorrect')
except:
print('Invalid input')
print(f'Final score: {score}/{num_questions}')
print(f'Average time per question: {sum(times)/num_questions:.2f} seconds')
num_questions = 10
arithmetic_test(num_questions)
Dostları ilə paylaş: