Asked by sofi

Mini Quiz Engine
Purpose: practice lists, loops, conditionals, scoring.
Concepts: list of (question,answer), for loop, enumerate, input, f‑strings.
Task:
Create a list of 5 short questions (mix T/F and MC).
Loop through questions, collect answers, give immediate feedback.
At the end print score and a short message.
code this

All Answers 1

Answered by GPT-5 mini AI
Here's a simple Python mini quiz engine that uses a list of (question, answer) pairs, loops with enumerate, collects input, gives immediate feedback, and prints a score + short message at the end.

```python
# Mini Quiz Engine

questions = [
("The Python keyword for defining a function is 'def'. (T/F)", "T"),
("Which is used to structure web page content?\nA) Python\nB) HTML\nC) C++\nD) Java\nAnswer:", "B"),
("The len() function returns the number of items in a list. (T/F)", "T"),
("Which of these is a loop in Python?\nA) for\nB) if\nC) class\nD) try\nAnswer:", "A"),
("Indentation is optional in Python. (T/F)", "F"),
]

score = 0

for i, (q, ans) in enumerate(questions, start=1):
user = input(f"Q{i}: {q} ").strip().upper()

# Normalize answers: accept T/F or full words, and A-D for MC
if user in ("TRUE", "T"):
user_norm = "T"
elif user in ("FALSE", "F"):
user_norm = "F"
elif user:
user_norm = user[0] # take first letter for MC (A/B/C/D)
else:
user_norm = ""

if user_norm == ans:
print("Correct!\n")
score += 1
else:
print(f"Incorrect. The correct answer is {ans}.\n")

total = len(questions)
pct = score / total * 100
print(f"You scored {score}/{total} ({pct:.0f}%).")

if score == total:
print("Perfect score — well done!")
elif score >= total * 0.6:
print("Nice work! A little more practice and you'll master it.")
else:
print("Keep practicing — you'll get there!")
```

Run this script in a Python 3 interpreter. It accepts answers like "T", "F", "True", "false", or letters "A"/"b" for multiple-choice.