3) b. For Loop Examples




Imagine you’re living in the allegorical land of Oz. The land with three witches. Your task is to kill Pink Eyes, the evil wizard of the South, using the magic words “Gotohellwitch!”. You’ve learned, from the book of witches, that every time you print that word to the witch you break one of the 10 strings giving life to the witch. Your task is to develop a python program that shall print the magic word 10 times before the witch and kill her. Write a code that kills Pink Eyes.

1
2
3
4
5
6
7
8
9
10
11
Output:
1. Gotohellwitch!
2. Gotohellwitch!
3. Gotohellwitch!
4. Gotohellwitch!
5. Gotohellwitch!
6. Gotohellwitch!
7. Gotohellwitch!
8. Gotohellwitch!
9. Gotohellwitch!
10. Gotohellwitch!




Pink Eyes has just discovered your plan to destroy her using your “magic” python code. She’s sent Kukuku, an evil cockroach, to harm you. Luckily, you’ve got a bottle with some magic charm that can kill Kukuku. You’ve, however, forgotten the password to open the magic bottle. You do remember, though, that the code was an odd number between 1500 and 1650. Also, that it was exactly divisible by 37.
Write a python code that shall list to you all the odd numbers between 1500 and 1650 which is also divisible by 37, in order to try finding the password before Kukuku harms you.

1
2
3
4
Output:
1517

1591




Your success at killing Kukuku and Pink Eyes using your “magic” python programming code has fascinated the entire land of Oz. Motomoto, the good witch of the West, has invited you to a mathematics contest to win the “Best Math Witch of Oz” award. You’ve learned from a friend that the mathematics challenge will involve counting numbers backward from 5678 to 5666. Write a code that will list all the numbers starting from 5678 to 5666 as your secret cheat-sheet.

1
2
3
4
5
6
7
8
9
10
11
12
13
Output:
5678
5677
5676
5675
5674
5673
5672
5671
5670
5669
5668
5667




Because you defeated Motomoto in the concluded competition, the people of Oz have allowed you to marry Nana the most beautiful lady of Oz. Sadly, Nana is still under the spell of Pink Eyes, the dead evil witch. To release her, you shall have to print “I love you so much” 15 times in the console. As Nana’s suitor, write a python that will release your bride from the spell of Pink Eyes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Output:
1. I love you so much
2. I love you so much
3. I love you so much
4. I love you so much
5. I love you so much
6. I love you so much
7. I love you so much
8. I love you so much
9. I love you so much
10. I love you so much
11. I love you so much
12. I love you so much
13. I love you so much
14. I love you so much
15. I love you so much




People in Oz have a problem understanding the difference between odd numbers and even numbers. The king of Oz has invited you to teach some of his wise men that difference. After the lesson, you are to give them a list of all numbers between 10 and 25 and specify if they are odd or even numbers. Write a code that will aid you to display the examples.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Output:
10 is an even number
11 is an odd number
12 is an even number
13 is an odd number
14 is an even number
15 is an odd number
16 is an even number
17 is an odd number
18 is an even number
19 is an odd number
20 is an even number
21 is an odd number
22 is an even number
23 is an odd number
24 is an even number
25 is an odd number