-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex1.py
31 lines (23 loc) · 758 Bytes
/
ex1.py
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
31
from random import randint
n = int(input("Range from 1 to >>: "))
print(f"Think of a number between 1 and {n}")
randnumber = randint(1,n) # a random number in a range between 1 to 5
def guessnumber ():
"""
guess a number in a given range
Args:(int n) input number from user
"""
counter = 1
while True:
number = int(input("Guess a number: "))
if number < randnumber:
print("Your guess too low")
elif number > randnumber:
print("Your Guess too high")
elif number == randnumber:
print(f"Good guess! You guessed your number {counter} tries")
break
counter += 1
if __name__ == "__main__":
output = guessnumber()
output