-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0011_guessing_game.py
More file actions
43 lines (32 loc) · 1017 Bytes
/
0011_guessing_game.py
File metadata and controls
43 lines (32 loc) · 1017 Bytes
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
38
39
40
41
42
43
import random
def get_integer(prompt):
"""Get an integer from Standard Input (stdin).
The function will continue looping, and prompting
the user, untial a valid `int` is entered.
:param prompt: The String that the user will see, when
they're prompted to enter the value
:return: The integer that the user enters.
"""
while True:
temp = input(prompt)
if temp.isnumeric():
return int(temp)
print("{0} is not a valid number".format(temp))
help(get_integer)
# print(input.__doc__)
# print("*" * 80)
# print(get_integer.__doc__)
# print("*" * 80)
highest = 10
answer = random.randint(1, highest)
print(answer) # todo: remove after testing
print("Please guess number between 1 and {}: ".format(highest))
while True:
guess = get_integer(": ")
if guess < answer:
print('Please guess higher')
elif guess > answer:
print('Please guess lower')
else:
print('You\'ve guessed it right')
break;