Uploaded by Clarisse Bianca Bucu

Week 1 Guessing Game

advertisement
Rose and Sam want to play a guessing game!
The rules of the game are as follows:
At the start of the game, Rose and Sam agree on the number of turns to play. Rose then
thinks of a number from 1 to 100 that she wants Sam to guess.
Each turn, Sam tells Rose his guess. Rose then replies with "Higher!" if the number she's
thinking of is higher than Sam's guess, "Lower!" if her number is lower than Sam's, or "You
win!" if Sam guesses the number correctly.
If Sam has used up all of his turns and has not guessed the number correctly, Rose replies
with "Sorry, better luck next time! The answer was ___."
Help them write a computer program to simulate their game!
Input Format
The first line is an integer , the number of turns to play.
The second line is an integer , the number Rose wants Sam to guess.
Each of the next lines contains a guess by Sam.
Constraints
.
.
for all in .
.
If , then (i.e. input guesses will continue until either a correct guess is given or the
maximum number of turns has been reached).
Output Format
The first lines of output contain one of three responses:
Higher! if ,
Lower! if , or
You win! if .
If inputs have been received, and , then the -th line will contain the response Sorry, better
luck next time! The answer was X. where is the original number to be guessed.
Sample Input 0
5
34
56
12
34
Sample Output 0
Lower!
Higher!
You win!
Sample Input 1
4
52
50
75
63
56
Sample Output 1
Higher!
Lower!
Lower!
Lower!
Sorry, better luck next time! The answer was 52.
Download