4) a. While Loop Examples (2)




You are sneaked into the annual meeting of the Quickie Games fanatics who are hungry for another game.. You have to write a program that plays with the user by deciding a secret number and let’s the user guess a number. Each time the user guesses a number the computer must inform him whether the secret number is greater or lesser than his number. Play continues until the user is able to guess the number.
You have 10 minutes to write a program that plays the game, otherwise, you will be killed by the fanatics.

1
2
3
4
5
6
7
8
9
Output:
Your choice: 40
Guess higher.
Your choice: 50
Guess higher.
Your choice: 60
Guess lower.
Your choice: 57
Congrats! You guessed it!




You are in the middle of nowhere searching for your family. You have found a computer in the nearest abandoned police station with a computer. On the computer, you can find a file with the name of every person who passed the city. The computer is so old, that you can open only a terminal. You quickly read the names from the file and put it into a list. Now write a program that reads the list and prints the first appearance of your parents’ name with the date when the passed. You can stop reading the list after you found your family.

1
2
3
4
5
6
Output:
i = 0
i = 1
i = 2
Found
Emily and Josh went West




You are in the house of your girlfriend. You have found a file, which is named my_boyfriends.txt. Your girlfriend is a little bit mad, so you must be sure, if she is writing about you. You have 10 minutes to search through the file, but it is impossible because it contains hundreds of lines.
Write a program that prints out the first line where your name appears. If there is no such line print that you are not
mentioned in the file.
Since you don’t know how to read files at this stage, assume that you are given a list of strings where every line is a new string.

1
2
3
Output:
Found your mention!
Emil hasn't given me any gems yet!




You are in the agency’s office and you just gained access to your commander’s computer. You searched a little bit and found a “list of tuples” containing the names of the criminal agents along with their influence levels.
Print out the agent names from the list, but you can skip the agents with a rank more than 4 because they cannot be arrested due to their influence factor.

1
2
3
Output:
('Jack', 3)
('Smith', 4)