-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlesson_15.py
More file actions
67 lines (58 loc) · 1.72 KB
/
Copy pathlesson_15.py
File metadata and controls
67 lines (58 loc) · 1.72 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
# for cycle, else, break, continue
name_list = ['Jim', 'Jack', 'Rickie', 'Mothes', 'Daniels']
friends_list = [
('John', 'Mitchell', None),
('Philip', 'Sadkovsky', 23),
('Anatoliy', 'Bloh', 12),
('Viola', 'Strachey', 19),
('Yoshi', 'Toochke', 27),
('Vasil', 'Semenyuk', 30),
('Jacky', 'Sun', 84),
('Jim', 'Mortison', None),
('Rickie', 'Clacson', 15),
('Mothes', 'Rubenstein', 31)
]
# Manipulations with friends average age
def friends_info(friends_list):
aver_age = 20;
age_type = ("young", "old")
sum_age = 0
f_with_age = 0
for friend_ in friends_list:
if friend_[2] is not None:
sum_age += int(friend_[2])
f_with_age += 1
aver_age = sum_age / f_with_age
print(f"Average age in the list is {aver_age} years.\n")
for friend_ in friends_list:
if friend_[2] is None:
continue
if friend_[2] < aver_age:
f_type = age_type[0]
else:
f_type = age_type[1]
print(f"{friend_[0]} is {f_type}, {friend_[2]}.")
# Calculating average name length from the names list
def aver_name_lenght(name_list):
names_l_sum = 0
for name_ in name_list:
name_l = len(name_)
names_l_sum += name_l
print(f"{name_} lenght is: {name_l}")
aver_l = names_l_sum / len(name_list)
print(f"\nAverage name lenght in this list is {aver_l}")
# Searching for name in list
def is_name_here(name_list, s_name):
name_is_in_list = False
for name_ in name_list:
if name_ is s_name:
name_is_in_list = True
break
if name_is_in_list:
print(f"Yeap, we have {s_name} in the list.")
else:
print(f"There's no name {s_name} in the list.")
#aver_name_lenght(name_list)
#is_name_here(name_list, "John")
#is_name_here(name_list, "Jack")
friends_info(friends_list)