-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday14–SpeakPython3.py
More file actions
94 lines (63 loc) · 1.92 KB
/
Copy pathday14–SpeakPython3.py
File metadata and controls
94 lines (63 loc) · 1.92 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
""" Day 14 – Speak Python 3
👉 Focus:
String analysis
Simple debugging
Project-style logic building"""
"""✅ Problem 1: Count Digits in a String
📌 Problem:
Write a function that takes a string and returns how many digits (0–9) it contains.
📎 Example:
count_digits("abc123") ➞ 3
count_digits("no digits") ➞ 0
count_digits("2024 is near") ➞ 4
⏱️ Target Time: 10 minutes"""
"""def count_digits(s):
count = 0
for char in s:
if char.isdigit():
count += 1
return count
s = "abc123"
print(count_digits(s))
print(count_digits("no digits"))
print(count_digits("2024 is near"))"""
"""🐞 Problem 2: Bug Fix – Find Max in List
📌 Bugged Code:"""
"""def find_max(lst):
max = lst[0]
for num in lst:
if num > max:
max = num
return max
print(find_max([-1, -2, -3])) # ➞ -1"""
"""🔍 Your Task:
Fix the bug so it correctly returns the max even for negative numbers.
🎯 Focus: Logical bug understanding
⏱️ Target Time: 7 minutes"""
# Bug fixed code:
"""def find_max(lst):
max = lst[0]
for num in lst:
if num > max:
max = num
return max
print(find_max([-1, -2, -3]))
print(find_max([1, 2, 3]))"""
"""⚒️ Problem 3: Micro Project – Remove Duplicates from List
📌 Problem:
Write a function that removes duplicates from a list and returns a new list with only unique elements (order preserved).
📎 Example:
remove_duplicates([1, 2, 2, 3, 4, 4, 4]) ➞ [1, 2, 3, 4]
remove_duplicates(["a", "b", "a", "c"]) ➞ ["a", "b", "c"]
💡 Hint: Use a loop and a helper list to check if an item is already added.
⏱️ Target Time: 15 minutes"""
"""def remove_duplicates(lst):
dup_rm = []
for i in lst:
if i in dup_rm:
continue
else:
dup_rm.append(i)
return dup_rm
print(remove_duplicates( [1, 2, 2, 3, 4, 4, 4]))
print(remove_duplicates( ["a", "b", "a", "c"]))"""