4) b. Break and Continue Statements Examples




Imagine that its 2059. There’s been an exodus of people from earth to Jupiter. Sadly, there’s a new Jupiter disease X that affects children under the age of 10 in Jupiter. The government wants you to develop a simple python code that issues tickets to people over the age of 10 years only. Can you help them develop it?

1
2
3
4
5
6
7
8
9
10
11
12
13
Output:
Would you like to continue? (Type "no" / Any other key to continue)
Please enter your name Oscar "Lazyjacks" Timbers
Please enter your age 31
Welcome aboard. Your id number is  2000

Would you like to continue? (Type "no" / Any other key to continue)
Please enter your name Davy "Loud Limey" Yelland
Please enter your age 9
Sorry Davy "Loud Limey" Yelland! Your entry is denied

Would you like to continue? (Type "no" / Any other key to continue) no
Remaining People =  2000




You are on the Earth in the year 2153. The year when humans started hating the aliens living among us. You must filter through news articles and find the positive ones about aliens helping humans (or vice versa) to prove to the people that we all share a brotherhood.
Given a list of news articles about human and alien interaction , write a program that iterates through every news article and filters only those where either side “helped” the other.

1
2
3
4
Output:
Fred the alien helped a human
The heartwarming tale of how one human and one alien helped each other overcome their physical handicaps
How John helped a baby alien who was dying in a pit




You are in a plane and the pilot just got ill. You have found a list of passengers and you need to find every doctor as soon as possible. On the plane there are 800 people, you cannot read the names one by one. Write a program that iterates through the list of the passengers and skips every name that doesn’t contain a “Dr.”.

1
2
3
4
5
Output:
Dr. Alan Grant
Dr. Evil
Dr. Victor
Dr. Yoda




You are a police officer, who wants to trap a serial killer. You have multiple witnesses waiting to be questioned. But you can ask every witness only 3 questions. If somebody says the name of the killer (Nikki Heat) than you can stop asking the questions and bring him into the station, otherwise continue asking questions. If you run out of questions you have to let the witness go. Write a program that asks 3 questions, reads the answers and works like described.

1
2
3
4
5
6
7
8
9
10
Output:
Guy#1
Asking question 0
Call him in for questioning.


Guy#2
Asking question 0
Asking question 1
Asking question 2




In military drills it is important to participate in every training. You, as the commander of the new squad, have to find if somebody was disrespectful and missed a training. Write a program that iterates through a list of your squad members. The list contains the attendance numbers. Write a program that prints the first member who wasn’t attendant to every training. If there is no such person print a message that the group is well-disciplined.

1
2
3
Output:
Squad#1 is well-disciplined
Squad#2 is not disciplined