-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz.py
More file actions
103 lines (83 loc) · 2.79 KB
/
quiz.py
File metadata and controls
103 lines (83 loc) · 2.79 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from classes import Quiz, Question
def create_sample_quiz():
"""Create a sample quiz with Python-related questions"""
quiz = Quiz()
# Add sample questions
quiz.add_question(
"What is the correct way to create a function in Python?",
[
"function myFunction():",
"def myFunction():",
"create myFunction():",
"func myFunction():",
],
"def myFunction():",
"In Python, functions are defined using the 'def' keyword.",
)
quiz.add_question(
"Which of the following is used to create a list in Python?",
["()", "[]", "{}", "<>"],
"[]",
"Lists in Python are created using square brackets [].",
)
quiz.add_question(
"What is the output of print(2 ** 3)?",
["6", "8", "5", "9"],
"8",
"The ** operator is used for exponentiation. 2^3 = 8.",
)
quiz.add_question(
"Which method is used to add an element to a list?",
["add()", "append()", "insert()", "push()"],
"append()",
"The append() method adds an element to the end of a list.",
)
quiz.add_question(
"What does the 'self' keyword represent in Python classes?",
[
"The class itself",
"The instance of the class",
"A reserved keyword",
"The parent class",
],
"The instance of the class",
"'self' refers to the instance of the class that is being created.",
)
quiz.add_question(
"what command is used to install packages in python",
["pop", "pap", "wow", "pip"],
"pip",
"pip is used to install python packages via the terminal",
)
return quiz
def main():
"""Main function to run the quiz app"""
print("🎯 Python Quiz App")
print("=" * 30)
while True:
print("\nOptions:")
print("1. Take the sample quiz")
print("2. Create a custom quiz")
print("3. Exit")
choice = input("\nEnter your choice (1-3): ").strip()
if choice == "1":
quiz = create_sample_quiz()
quiz.run_quiz()
elif choice == "2":
print("\nCustom quiz feature coming soon!")
print("For now, enjoy the sample quiz!")
elif choice == "3":
print("👋 Thanks for playing! Goodbye!")
break
else:
print("❌ Invalid choice! Please enter 1, 2, or 3.")
# Ask if user wants to play again
if choice in ["1", "2"]:
play_again = (
input("\nWould you like to play again? (y/n): ").lower().strip()
)
if play_again != "y":
print("👋 Thanks for playing! Goodbye!")
break
if __name__ == "__main__":
main()