-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday17_speakPython6.py
More file actions
90 lines (58 loc) · 2.02 KB
/
Copy pathday17_speakPython6.py
File metadata and controls
90 lines (58 loc) · 2.02 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
"""Day 17 – Speak Python 6
👉 Focus:
Conditionals Practice
Logical Thinking
String/Number Conversion
Mini Project Practice"""
"""✅ Problem 1: Armstrong Number Checker
📌 Problem:
Write a function that checks whether a number is an Armstrong number.
An Armstrong number is a number that is equal to the sum of its digits each raised to the power of the number of digits.
📎 Example:
armstrong_check(153) ➞ True
(1³ + 5³ + 3³ = 153)
armstrong_check(123) ➞ False
💡 Hint: Use str() to get digits, then ** for power.
⏱️ Target Time: 10 minutes"""
"""def armstrong_check(digits):
sum = 0
for n in str(digits):
power = int(n) ** len(str(digits))
sum += power
return sum == digits
print(armstrong_check(234))
print(armstrong_check(153))
print(armstrong_check(12))"""
"""🐞 Problem 2: Bug Fix – Reverse Words
📌 Bugged Code:"""
"""def reverse_words(sentence):
words = sentence.split()
words.reverse()
return words.join(" ")
print(reverse_words("Python is awesome")) # ➞ "awesome is Python"""
#Bugfixed code:
"""def reverse_words(sentence):
words = sentence.split()
words.reverse()
return " ".join(words)
print(reverse_words("Python is awesome")) # ➞ "awesome is Python"""
"""🔍 Your Task:
Fix the bug so it correctly returns the reversed sentence.
🎯 Focus: String + list method bug fixing
⏱️ Target Time: 7 minutes"""
"""⚒️ Problem 3: Micro Project – Word Frequency Counter
📌 Problem:
Write a function that counts how many times each word appears in a sentence and returns a dictionary.
📎 Example:
count_words("apple banana apple orange banana apple")
➞ {'apple': 3, 'banana': 2, 'orange': 1}
💡 Hint: Use .split() and dictionary.
⏱️ Target Time: 15 minutes"""
"""def count_words(s):
words = s.split(" ")
dict = {}
for word in words:
count = words.count(word)
dict.update({word : count})
return dict
print(count_words( "apple banana apple orange banana apple"))"""