-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber-guessing-game.py
More file actions
30 lines (29 loc) · 1.04 KB
/
number-guessing-game.py
File metadata and controls
30 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'''
Objective: At start-up, the user enters the smallest number
and the largest number in the range.
The computer then selects a number from this range.
On each pass through the loop, the user enters a number
to attempt to guess the number selected by the computer.
The program responds by saying
“You’ve got it,” “Too large, try again,” or “Too small, try again.”
When the user finally guesses the correct number,
the program congratulates him and tells him the total number of guesses.
Author: Sarju S
Date: 14-11-2024
'''
import random
smallest = int(input("Enter a small number: "))
largest = int(input("Enter a a big number: "))
guess= random.randint(smallest,largest)
no_of_tries= 0
while True:
user_input = int(input("Guess a number: "))
no_of_tries+=1
if user_input < guess:
print("Too small, enter a bigger number")
elif user_input > guess:
print("Too big, enter a smaller number")
else:
print("Congrats! You guessed the number!")
print("The number of tries is", no_of_tries)
break