-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter8.html
More file actions
295 lines (255 loc) · 8.56 KB
/
Copy pathchapter8.html
File metadata and controls
295 lines (255 loc) · 8.56 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chapter 8 - String Editing</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
<style>
body {
margin: 0;
background: linear-gradient(135deg , #1a0033, #000000 , #000000);
min-height: 100vh;
font-family: 'Courier New', monospace;
color: white;
display: flex;
flex-direction: column;
align-items: center;
}
.back-link {
color: rgba(255, 255, 255, 0.7);
text-decoration: none;
align-self: flex-start;
margin: 20px 30px;
}
.panel {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 24px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
padding: 40px;
width: 350px;
margin-bottom: 40px;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
.panel.wide {
width: min(900px, 90vw);
}
.motivation {
font-style: italic;
color: rgba(255, 255, 255, 0.8);
}
.lesson-links {
display: flex;
flex-direction: column;
gap: 12px;
margin: 25px 0;
}
.link-btn {
background: rgba(255, 255, 255, 0.15);
padding: 10px 28px;
border-radius: 50px;
color: white;
text-decoration: none;
transition: transform 0.2s, box-shadow 0.2s;
}
.link-btn:hover {
transform: translateY(-4px);
box-shadow: 0 10px 25px rgba(168, 85, 247, 0.5);
}
.start-btn {
display: inline-block;
font-family: inherit;
padding: 14px 45px;
background: linear-gradient(135deg, #ff6ec7, #a855f7);
color: white;
border: none;
border-radius: 50px;
font-size: 16px;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
margin-top: 20px;
}
.start-btn:hover {
transform: translateY(-4px);
box-shadow: 0 10px 25px rgba(168, 85, 247, 0.5);
}
.hidden { display: none; }
.solutions {
width: 100%;
text-align: left;
margin-top: 25px;
}
.solution {
background: rgba(0, 0, 0, 0.3);
border-radius: 12px;
padding: 15px;
margin-bottom: 20px;
}
.filename {
color: #00ff00;
font-size: 14px;
margin: 0 0 10px 0;
}
.solution pre {
background: rgba(0, 0, 0, 0.4);
padding: 15px;
border-radius: 8px;
overflow-x: auto;
white-space: pre-wrap;
margin: 0;
text-align: left;
}
.done-btn {
background: transparent;
border: 2px solid #00ff00;
color: #00ff00;
font-family: inherit;
font-size: 16px;
padding: 14px 40px;
border-radius: 50px;
margin-top: 20px;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
.done-btn:hover {
transform: translateY(-4px);
box-shadow: 0 10px 25px rgba(0, 255, 0, 0.3);
}
.footer-content { text-align: center; }
.footer-social { margin-top: 10px; }
.github-support-link {
color: #00ff00;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 8px;
}
.github-support-link:hover { color: #00cc00; }
</style>
</head>
<body>
<a class="back-link" href="progress.html">← Back to Chapters</a>
<div class="panel wide">
<h1>Chapter 8</h1>
<p class="motivation">String Editing is hardeer than video editing - 'My Friend who thinks Capcut is indian'</p>
<div class="lesson-links">
<a class="link-btn" href="https://automatetheboringstuff.com/3e/chapter8.html" target="_blank" rel="noopener">Read the Lesson (ATBS)</a>
<a class="link-btn" href="https://inventwithpython.com/automate3workbook/chapter8.html" target="_blank" rel="noopener">(Invent with Python)</a>
</div>
<button id="btn-solutions" class="start-btn">Show Solutions</button>
<div id="solutions" class="solutions hidden">
<div class="solution">
<h3 class="filename">diagStripe.py</h3>
<pre class="language-python"><code>
import time
og_list = []
new_list =[]
for i in range(50):
exp = i*'O'
og_list.append(exp.rjust(i , '.') + (50 -i)*'.')
for i in range(50):
newexp = i * 'O'
new_list.append((50-i)*'.' + newexp.rjust(i , '.'))
og_list = og_list
new_list = new_list
reversed_list = list(reversed(new_list))
while True:
for i in og_list:
print(i)
time.sleep(0.01)
for j in reversed_list:
print(j)
time.sleep(0.01)
</code></pre>
</div>
<div class="solution">
<h3 class="filename">mockingSpongebob.py</h3>
<pre class="language-python"><code>def spongecase(sentence):
if not isinstance(sentence , str):
return 'Invalid Input'
new_sentence = ''
convert = 'lower'
for i in sentence:
if i.isalpha():
if convert == 'lower':
new_sentence += i.lower()
convert = 'upper'
elif convert == 'upper':
new_sentence += i.upper()
convert = 'lower'
else:
new_sentence += i
return new_sentence
sentence = input('Enter your sentence: \n')
print(spongecase(sentence))
</code></pre>
</div>
<div class="solution">
<h3 class="filename">wordMatchGame.py</h3>
<pre class="language-python"><code>value = False
import random
def get_word_hint(secret_word , guess_word):
if not len(guess_word) == 5:
return 'Invalid Input!\n'
hint = ''
for i in range(5):
if secret_word[i].lower() == guess_word[i].lower():
hint += 'O'
elif guess_word[i].lower() in secret_word.lower():
hint += 'o'
else:
hint += 'x'
return hint + '\n'
secret_word = 'MITTS FLOAT BRICK LIKED DWARF COMMA GNASH ROOMS UNITE BEARS SPOOL ARMOR'.split()
secret_word = random.choice(secret_word)
print('Guess the secret five-letter word:')
for i in range(6):
guess = input('')
response = get_word_hint(secret_word , guess)
print(response)
if response.strip() == 'OOOOO':
print('Your guess is correct')
value = True
break
if value == False:
print(f'The secret word was {secret_word}. Better luck next time.')
</code></pre>
</div>
</div>
<a id="btn-done" class="done-btn" href = 'progress.html' onclick="markDone(8)">Mark as Done</a>
</div>
<footer class="site-footer">
<div class="footer-content">
<p>© All rights reserved.</p>
<div class="footer-social">
<a href="https://github.com/PeacefulPolymath/Peaceful-Python-LPP" target="_blank" rel="noopener noreferrer" class="github-support-link">Star or Support on GitHub</a>
</div>
</div>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>
function markDone(n) {
var prev = parseInt(localStorage.getItem('lppDone') || '0', 10);
if (n > prev) localStorage.setItem('lppDone', String(n));
}
const btn = document.getElementById('btn-solutions');
let highlighted = false;
btn.addEventListener('click', () => {
const box = document.getElementById('solutions');
box.classList.toggle('hidden');
btn.textContent = box.classList.contains('hidden') ? 'Show Solutions' : 'Hide Solutions';
if (!highlighted) {
box.querySelectorAll('pre code').forEach((block) => {
hljs.highlightElement(block);
});
highlighted = true;
}
});
</script>
</body>
</html>