-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththe-terminal-deeper-quiz.py
More file actions
173 lines (159 loc) · 6.14 KB
/
the-terminal-deeper-quiz.py
File metadata and controls
173 lines (159 loc) · 6.14 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"""
Quiz: The Terminal — Going Deeper
Review: concepts/the-terminal-deeper.md
"""
from _quiz_helpers import normalize_answer
def run_quiz():
print("=" * 60)
print(" QUIZ: The Terminal — Going Deeper")
print(" Review: concepts/the-terminal-deeper.md")
print("=" * 60)
print()
score = 0
total = 7
# Question 1
print("Question 1/7: What does the pipe symbol | do in the terminal?")
print()
print(" a) Separates two unrelated commands")
print(" b) Sends the output of one command as input to the next")
print(" c) Runs two commands at the same time")
print(" d) Creates a new file")
print()
answer = normalize_answer(input("Your answer: "))
if answer == "b":
score += 1
print("Correct! The pipe connects commands. The output of the")
print("left command becomes the input of the right command.")
else:
print("Incorrect. The answer is b).")
print("Example: ls | wc -l counts files by piping the file list")
print("into the line counter.")
print()
# Question 2
print("Question 2/7: What is the difference between > and >> ?")
print()
print(" a) > is for text files, >> is for binary files")
print(" b) > overwrites the file, >> appends to the end")
print(" c) > creates a file, >> deletes a file")
print(" d) They do the same thing")
print()
answer = normalize_answer(input("Your answer: "))
if answer == "b":
score += 1
print("Correct! > writes output to a file (replacing contents).")
print(">> adds output to the end of an existing file.")
else:
print("Incorrect. The answer is b).")
print("> overwrites, >> appends. Use >> to add to logs without")
print("losing previous content.")
print()
# Question 3
print("Question 3/7: What does Ctrl+C do in the terminal?")
print()
print(" a) Copies text to clipboard")
print(" b) Clears the screen")
print(" c) Stops the currently running command")
print(" d) Closes the terminal")
print()
answer = normalize_answer(input("Your answer: "))
if answer == "c":
score += 1
print("Correct! Ctrl+C sends an interrupt signal that stops the")
print("current process. Essential for stopping infinite loops.")
else:
print("Incorrect. The answer is c).")
print("Ctrl+C interrupts the running command. It does not copy")
print("text in the terminal (that is different from GUI copy).")
print()
# Question 4
print("Question 4/7: What does this command do?")
print()
print(" export API_KEY='abc123'")
print()
print(" a) Installs the API_KEY package")
print(" b) Sets an environment variable for the current session")
print(" c) Saves API_KEY permanently to a file")
print(" d) Sends abc123 to an API")
print()
answer = normalize_answer(input("Your answer: "))
if answer == "b":
score += 1
print("Correct! export sets an environment variable that programs")
print("can read. It lasts only for the current terminal session.")
else:
print("Incorrect. The answer is b).")
print("export creates a temporary environment variable. Programs")
print("read it with os.environ in Python.")
print()
# Question 5
print("Question 5/7: What does && do between commands?")
print()
print(" python -m pytest && echo 'All tests passed!'")
print()
print(" a) Runs both commands regardless of success")
print(" b) Runs the second command only if the first succeeds")
print(" c) Runs both commands at the same time")
print(" d) Combines the output of both commands")
print()
answer = normalize_answer(input("Your answer: "))
if answer == "b":
score += 1
print("Correct! && means 'run the next command only if the")
print("previous one succeeded (exit code 0).'")
else:
print("Incorrect. The answer is b).")
print("&& is conditional: the second command runs only on success.")
print("Use ; to run regardless, || to run only on failure.")
print()
# Question 6
print("Question 6/7: Why should .env files not be committed to git?")
print()
print(" a) They are too large")
print(" b) They contain secrets like API keys and passwords")
print(" c) Git cannot read .env files")
print(" d) They slow down the repository")
print()
answer = normalize_answer(input("Your answer: "))
if answer == "b":
score += 1
print("Correct! .env files contain sensitive configuration like")
print("API keys and database passwords. Add .env to .gitignore.")
else:
print("Incorrect. The answer is b).")
print("Committing secrets to git is a security risk. Anyone")
print("with access to the repo can see them.")
print()
# Question 7
print("Question 7/7: What does the 'which python' command show you?")
print()
print(" a) The version of Python installed")
print(" b) The file path where the python command lives")
print(" c) A list of all Python packages")
print(" d) Whether Python is installed")
print()
answer = normalize_answer(input("Your answer: "))
if answer == "b":
score += 1
print("Correct! 'which' shows the full path to the command.")
print("Useful for checking if you are using the right Python")
print("(system vs virtual environment).")
else:
print("Incorrect. The answer is b).")
print("'which python' might show /usr/bin/python or .venv/bin/python,")
print("telling you exactly which Python you are using.")
print()
# Final score
print("=" * 60)
pct = round(score / total * 100)
print(f" Final Score: {score}/{total} ({pct}%)")
print()
if pct == 100:
print(" Perfect! You are comfortable with advanced terminal use.")
elif pct >= 70:
print(" Good work! Review the questions you missed.")
else:
print(" Keep practicing! Re-read concepts/the-terminal-deeper.md")
print(" and try again.")
print("=" * 60)
if __name__ == "__main__":
run_quiz()