Предмет: Информатика,
автор: ydsidorchuk2010
Даю 100 балів! Створити код в пайтоні, щоб виводило 12 питань по типу 2+3, потім щоб виводило кількість правильних та не правильних відповідей та в кінці оцінку, за кожну правильну відповідь по 1 балу
Ответы
Автор ответа:
1
Я не уверен но вроде вот
import random
def generate_question():
num1 = random.randint(1, 10)
num2 = random.randint(1, 10)
operator = random.choice(['+', '-', '*', '/'])
question = f"{num1} {operator} {num2}"
answer = eval(question)
return question, answer
def quiz(num_questions):
correct_answers = 0
incorrect_answers = 0
for _ in range(num_questions):
question, correct_answer = generate_question()
user_answer = input(f"What is the answer to {question}? ")
try:
user_answer = float(user_answer)
if user_answer == correct_answer:
print("Correct!")
correct_answers += 1
else:
print(f"Wrong! The correct answer is {correct_answer}.")
incorrect_answers += 1
except ValueError:
print("Invalid input. Moving to the next question.")
incorrect_answers += 1
print("\nQuiz Results:")
print(f"Correct Answers: {correct_answers}")
print(f"Incorrect Answers: {incorrect_answers}")
total_score = correct_answers * 1 # 1 point for each correct answer
print(f"Your Score: {total_score}/{num_questions}")
if total_score == num_questions:
print("Congratulations! You got a perfect score!")
elif total_score >= num_questions / 2:
print("Well done! You did fairly well.")
else:
print("Keep practicing. You can do better!")
# Запустити тест із 12 питань
quiz(12)
import random
def generate_question():
num1 = random.randint(1, 10)
num2 = random.randint(1, 10)
operator = random.choice(['+', '-', '*', '/'])
question = f"{num1} {operator} {num2}"
answer = eval(question)
return question, answer
def quiz(num_questions):
correct_answers = 0
incorrect_answers = 0
for _ in range(num_questions):
question, correct_answer = generate_question()
user_answer = input(f"What is the answer to {question}? ")
try:
user_answer = float(user_answer)
if user_answer == correct_answer:
print("Correct!")
correct_answers += 1
else:
print(f"Wrong! The correct answer is {correct_answer}.")
incorrect_answers += 1
except ValueError:
print("Invalid input. Moving to the next question.")
incorrect_answers += 1
print("\nQuiz Results:")
print(f"Correct Answers: {correct_answers}")
print(f"Incorrect Answers: {incorrect_answers}")
total_score = correct_answers * 1 # 1 point for each correct answer
print(f"Your Score: {total_score}/{num_questions}")
if total_score == num_questions:
print("Congratulations! You got a perfect score!")
elif total_score >= num_questions / 2:
print("Well done! You did fairly well.")
else:
print("Keep practicing. You can do better!")
# Запустити тест із 12 питань
quiz(12)
p15:
ИИ не о всем подумал. На вопросы с делением (на большинство) вы скорее всего не ответите.
Похожие вопросы
Предмет: Английский язык,
автор: muradovasatarat
Предмет: История,
автор: derekasergej94
Предмет: Математика,
автор: evaeva26042013
Предмет: Английский язык,
автор: erygdryhgfr
Предмет: Математика,
автор: prepelicaulia