-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path# python quiz game.py
68 lines (56 loc) · 2.45 KB
/
# python quiz game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# python quiz gameA
questions = (
"What is an Accumulator (ACC)?",
"What is an address bus?",
"What is the Arithmetic Logic Unit (ALU)?",
"What are Buses?",
"What is Cache?"
)
options = (
("A. A special register to temporarily store the results of operations performed by the ALU.",
"B. Carries the memory location address of the register the data is being carried to or from.",
"C. A part of the CPU that performs arithmetic calculations and logical operations on data for the computer programs",
"D. A physical set of parallel wires connecting and carrying groups of bits between several components of a computer.",
"E. A small and fast but expensive memory in the CPU used to store instructions and data that are accessed regularly."),
("A. A small memory register.",
"B. Carries the memory location address of the register.",
"C. Performs arithmetic calculations and logical operations.",
"D. Parallel wires connecting components.",
"E. Fast memory storing instructions and data."),
("A. Temporarily stores ALU results.",
"B. Address bus for carrying data.",
"C. The CPU component performing calculations.",
"D. Wires connecting computer components.",
"E. CPU memory storing frequently accessed data."),
("A. Stores temporary results.",
"B. Carries memory location addresses.",
"C. Performs arithmetic and logic operations.",
"D. Wires connecting components in a computer.",
"E. Cache memory for frequently used instructions."),
("A. A temporary storage register.",
"B. Carries address of data transfer.",
"C. CPU performs calculations here.",
"D. Physical wires carrying data.",
"E. Fast storage for frequently accessed data."),
)
answers = ("A", "B", "C", "D", "E") # Correct answers for each question
guesses = []
score = 0
question_num = 0
# Loop through each question
for question in questions:
print(f"\nQuestion {question_num + 1}: {question}")
for option in options[question_num]:
print(option)
guess = input("Enter your answer (A, B, C, D, E): ").upper()
guesses.append(guess)
if guess == answers[question_num]:
print("Correct!")
score += 1
else:
print("Wrong!")
print(f"The correct answer was: {answers[question_num]}")
question_num += 1
# Display final score
print("\nQuiz completed!")
print(f"Your score is {score} out of {len(questions)}.")