5) h. Generators and Generator Expressions Examples (2)




You are a special agent working for the Federation. Your only job is to hide the messages sent by them to their
agents. Be careful! If you can see a message two times one of your agents will die. You don’t know who will receive
the message or what it is containing. You just send a blank message.
Write a program that prints different message after each call (use yield) to avoid sending a message two times.

1
2
3
4
Output:
Agent 19 must go to Wien to save the most valued necklace
Agent 99 have to stay home because he got infected with corona
Agent 07 need to go to Berlin to find out the new leader's name




In the middle of nowhere, you found a computer. After a little investigation, you realized that it contains some data, but you cannot see without a specific program. The data must be a set of messages, but you need to know what they contain exactly because it can help you in your salvation.
Write a program that iterates through your data structure. You must write a function that gets the message block as input and after every call writes out the next element. Write out the whole content of the data to find your way.

1
2
3
4
5
6
7
Output:
Go in the tree's direction 10 steps
Turn left 30 degrees
Go straigt 4 steps
Turn 40 degrees North
Go straigt 4 km
You found your way out




In the Third World War, you need to track the Agency’s messages. You find out that they are coding their messages, but you know that their coding is to reverse the words. For your country, you need to write a program that reverses every word from a message. Be careful, for modifying the message you can use only yield operator, otherwise the enemy will know that you find out their coding system and you are able to decode their calls.

1
2
Output:
The decoded message is: the attack is postponed




You are a time traveler and you came back to 2020. You know that there is a pandemic killing people on the planet but you know exactly when to stop it. You need to find out the square of the currently infected people, but be aware because you need to be flexible because the database is updating constantly.
Write a program that calculates the next element’s square in each cell, but not before the call. Don’t forget! Humanity is depending on you.

1
2
3
4
5
6
Output:
9
225
16
6084
25




You are in the middle of the Coronavirus outbreak. The virus is spreading exponentially. You need to know how many infected people will be in 30 rounds if an infected person infects only two other ones, who also infects 2 people each. A round is represented as an infection (the first person infects 2, in the second round the two infected people infects other 2-2, etc).
Write a program that calculates the total number of infected people after 30 rounds.

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
Output:
1
 
2
 
4
 
8
 
16
 
32
 
64
 
128
 
256
 
512
 
1024
 
2048
 
4096
 
8192
 
16384
 
32768
 
65536
 
131072
 
262144
 
524288
 
1048576
 
2097152
 
4194304
 
8388608
 
16777216
 
33554432
 
67108864
 
134217728
 
268435456
 
536870912