-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHW17_args_kwargs.py
More file actions
55 lines (39 loc) · 1.25 KB
/
HW17_args_kwargs.py
File metadata and controls
55 lines (39 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
51
52
53
54
55
#Task 1
# def sum_numbers(*args):
# s = 0
# for i in args:
# s += i
# return s
# print(sum_numbers(10,20,30,40))
#Task 2
# def print_kwargs(**kwargs):
# d = kwargs.items()
# for i in d:
# print(f"{i[0]}: {i[1]}")
# print_kwargs(name='Alice', age=25, country='USA')
#Task 3
# def filter_by_length(*args, **kwargs):
# min_length = kwargs.get("min_length", 1000)
# ans = []
# for i in args:
# if len(i) >= min_length:
# ans.append(i)
# print(filter_by_length("hello", "world", "how", "are", "you", min_length=4))
#Task 4
# def calculate_total_price(cost, **kwargs):
# total_discount = 0
# for key, value in kwargs.items():
# total_discount += value
# return print(cost * (100-total_discount) / 100)
# calculate_total_price(100, student=10, coupon=20)
# calculate_total_price(200, holuday=25)
# calculate_total_price(500)
#Task 5
# def custom_print(*args, **kwargs):
# sep = kwargs.pop('sep', ' ')
# end = kwargs.pop('end', '\n')
# items = [f"{k}={v}" for k, v in kwargs.items()]
# print(*args, sep=sep, end = sep)
# print(*items, sep=sep, end = end)
# custom_print(1, 2, 3, a=4, b=5, sep='-', end='!')
# custom_print('Hello', 'World', sep=' ')