-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday8.py
More file actions
50 lines (36 loc) · 1.25 KB
/
Copy pathday8.py
File metadata and controls
50 lines (36 loc) · 1.25 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
"""🏁 Day 8 – Problem Solving Pack
🔹 String formatting
🔹 Basic math logic
🔹 Conditionals"""
"""✅ 🔶 Problem 1: Format Phone Number
Problem:
Write a function that takes a list of 10 integers (0–9) and returns them as a formatted phone number string like (123) 456-7890.
Example:
format_phone([1,2,3,4,5,6,7,8,9,0]) ➞ "(123) 456-7890"""
def format_phone(numbers):
if len(numbers) != 10:
return "This numbers is invalid"
else:
area = "".join(str(i) for i in numbers[0:3])
middle = "".join(str(i) for i in numbers[3:6])
last = "".join(str(i) for i in numbers[6:10])
return f"({area}) {middle}-{last}"
print(format_phone([8,8,8,4,5,6,7,8,9,9]))
print(format_phone([1,2,3,4,5,6,7,8,9]))
print(format_phone([1,2,3,4,5,6,7,8,9,0]))
print(format_phone([8,8,8,4,5,6,7,8,9,9,3]))
"""✅ 🔶 Problem 2: Make a List of Multiples
Problem:
Write a function that returns a list of the first n multiples of a given number x.
Example:
multiples(3, 5) ➞ [3, 6, 9, 12, 15]
multiples(2, 4) ➞ [2, 4, 6, 8]"""
def multiples(n, x):
mul = []
for m in range(1, x+1):
ml = m * n
mul.append(ml)
return mul
print(multiples(3, 5))
print(multiples(2, 4))
print(multiples(15, 10))