Is Too Low." Go Back To Step 3. Is Too High." Go Back To Step 3. Correctly. Press Enter To Play Again. Type Exit' To Exit The Program." and

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

7.

Mini Project - Guess the Number

You have to build a program that will first randomly generate a number unknown to the user.
The user needs to guess what that number is. (In other words, the user needs to be able
to input information.)

Flow of the program:

1. Welcome the user to the program.


2. Choose a random integer number between 0 and 100.
3. Ask the user to guess the number.
a. If the user’s input is not an integer between 0 and 100, tell them that the input is
not a valid one, and go back to step 3.
b. If the user’s input is a positive integer number, compare the user’s guess with
the randomly chosen number:
i. If the user’s guess is lower than the chosen number, display “Your guess
is too low.” Go back to step 3.
ii. If the user’s guess is higher than the chosen number, display “Your guess
is too high.” Go back to step 3.
iii. If the user’s guess is equal to the chosen number, display “You guessed
correctly. Press Enter to play again. Type ‘exit’ to exit the program.” and
ask the user for the input.
1. If user presses Enter, go back to step 2.
2. If the user types ‘exit’, exit the program.

Concepts to keep in mind:

 Random function
 Variables
 Integers
 Input/Output
 Print
 While loops
 If/Else statements

Qëndrim Krasniqi
An example of how it might work:

Welcome to Guess a number game.

Please type 'exit' to exit the program.

Guess an integer number between 0 and 100: 50


Your guess is too high.

Guess an integer number between 0 and 100: 25


Your guess is too high.

Guess an integer number between 0 and 100: 12


Your guess is too high.

Guess an integer number between 0 and 100: 6


Your guess is too low.

Guess an integer number between 0 and 100: 9


Your guess is too high.

Guess an integer number between 0 and 100: 7


Your guess is correct.

Press Enter to play again, or type "exit" to exit the program:

Guess an integer number between 0 and 100: 70


Your guess is too high.

Guess an integer number between 0 and 100: 30


Your guess is too high.

Guess an integer number between 0 and 100: 10


Your guess is too high.

Guess an integer number between 0 and 100: 5


Your guess is too low.

Guess an integer number between 0 and 100: 7


Your guess is too low.

Guess an integer number between 0 and 100: 8


Your guess is correct.

Press Enter to play again, or type "exit" to exit the program: exit
>>>

Qëndrim Krasniqi

You might also like