3) g. Iterators and Iterables Examples (2)




You are at a woman’s house who is stalking on you. Meanwhile, she went out to get some drinks you managed to open her laptop.
You have five minutes to check a file she has about you, but you can’t open because she would see that you saw it. Write a program that iterates through the file’s content line by line and writes out the content. You have the file in a list of string. Use iter and next iterators.

1
2
3
4
5
6
Output:
He is selfish
He was at the Curry House today at 5PM
He was talking to a girl at the corner of 5th street
He was wearing a red tie with blue suits
I think he has somebody, because he has bought a bouquet of roses




You had a terrible accident which made you forget how to separate letters into words but somehow you still know how to type using a keyboard.
Your survival depends upon this knowledge, so you have to learn how to separate again.
To save your life you must write a program that separates a text letter by letter using iterators.

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
91
92
93
94
95
Output:

M
y
 
n
a
m
e
 
i
s
 
J
o
h
n
 
S
m
i
t
h
 
a
n
d
 
I
 
w
i
l
l
 
l
e
a
r
n
 
w
i
t
h
 
t
h
i
s
 
t
e
x
t
 
h
o
w
 
t
o
 
s
e
p
a
r
a
t
e
 
a
 
t
e
x
t
 
l
e
t
t
e
r
 
b
y
 
l
e
t
t
e
r




You are closed in a room and the only way to escape is to find the key to the door, but you have thousands of keys.
Each key has a sticky with a name on it. You have 10 minutes to find your key, so you have to write a program, that lists every sticky from the keys.

1
2
3
4
5
6
7
8
9
10
11
Output:
Rylee Mcloughlin
Nathanael Hagan
Toni Barlow
Giselle Charlton
Leonardo Easton
Daria Ali
Adaline Goodman
Paloma Reed
Cherie Rowe
Maya Hayden




At the II WW, it is important to know what are your enemies doing. You have spied a message but unfortunately, it is coded. To decode the message you need to move each character one step forward in the alphabet. If the character is 0, then the decoded one is ‘a’, and if the coded is ‘z’ then the decoded is a space.
Write a program that decodes a message, to be able to react to the attack as fast as you can.

1
2
3
Output:
Sgdz0ss0bjzvhkkzadzsnlnqqnvz0sz4zOL
The attack will be tomorrow at 5 PM




The world is under an alien invasion. You are stuck in a house full of weapons and ammunition, but you have to know which weapons bring with yourself. You don’t want to bring any unnecessary weight with you which means if you have no ammunition for a weapon you will leave it there.
Write a program that iterates through your ammunition and prints to the screen to be able to decide which weapons to bring with you. Use your own iterator class.

1
2
3
4
5
6
7
8
9
Output:
0.092
0.172
0.183
0.223
0.205
0.107
0.12
0.23