-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise2.py
More file actions
35 lines (24 loc) · 846 Bytes
/
exercise2.py
File metadata and controls
35 lines (24 loc) · 846 Bytes
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
"""
1) Create a list of names and use a for loop to output the length of each name (len()).
2) Add an if check inside the loop to only output names longer than 5 characters.
3) Add another if check to see whether a name includes a “n” or “N” character.
4) Use a while loop to empty the list of names (via pop())
"""
names = ['Bob', 'Chris', 'Micheal', 'David',
'Fernando Torres', 'Thomas Muller', 'Wendy']
def contains(name, patterns):
for pattern in patterns:
if pattern in name:
return True
return False
for name in names:
print(len(name))
for name in names:
if len(name) > 5:
print(name)
for name in names:
if len(name) > 5 and contains(name, ['n', 'N']):
print(name)
while len(names) > 0:
names.pop()
print(names)