-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuess_the_number_2v2.py
37 lines (31 loc) · 1.03 KB
/
Guess_the_number_2v2.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
32
33
34
35
36
37
def user_input():
"""Return proper value provided by user.
:rtype: str
:return: value provided by user from ["too small", "too big", "you won"]
"""
possible_input = ["too small", "too big", "you won"]
while True:
user_answer = input().lower()
if user_answer in possible_input:
break
print("Input is not in ['too small', 'too big', 'you won']")
return user_answer
def guess_the_number():
"""Main function for our program."""
print("Imagine number between 0 and 1000!")
print("Press 'Enter' to continue")
input()
min_number = 0
max_number = 1000
user_answer = ""
while user_answer != "you won":
guess = (max_number - min_number) // 2 + min_number
print(f"Your number is: {guess}")
user_answer = user_input()
if user_answer == "too big":
max_number = guess
elif user_answer == "too small":
min_number = guess
print("Hurra! I guess!")
if __name__ == '__main__':
guess_the_number()