-
Notifications
You must be signed in to change notification settings - Fork 2
/
guess_it.py
executable file
·79 lines (72 loc) · 2.05 KB
/
guess_it.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
__author__ = "Jugal Kishore"
__version__ = "1.0"
from random import randint
def newline():
print("")
print("///Random Number Guessing Game///")
newline()
print("Rules: -")
newline()
print(" ~ This program will generate a random integer between 0 and 20")
print(" ~ You will get three attempts to guess it")
print(" ~ If you can't guess in three attempts, it will exit")
attempt = 3
newline()
while attempt > 0:
if attempt == 3:
random_number = randint(0, 20)
print("Integer generated successfully")
newline()
print("Available Attempts: {0}".format(attempt))
newline()
print("Enter an integer:")
try:
number = int(input())
except ValueError:
newline()
print("Not an integer")
attempt -= 1
continue
if number == random_number:
newline()
print("You guessed it right!")
newline()
print("Random generated was indeed =", random_number)
newline()
print("Play Again?")
print(" ~ 'y' for yes, anything else to exit")
temp = input()
if temp == "y":
attempt = 3
continue
else:
newline()
print("Exiting!")
break
elif number > random_number:
if number > 20 or number < 0:
newline()
print("The entered number should be in range [0,20]")
else:
newline()
print(
"Uh-huh, you guessed a little more than the generated number, try again"
)
else:
if number > 20 or number < 0:
newline()
print("The entered number should be in range [0,20]")
else:
newline()
print(
"Uh-huh, you guessed a little less than the generated number, try again"
)
attempt -= 1
if attempt == 0:
newline()
print("Ran out of attempts")
print("Exiting!")
newline()
print("Created by Jugal Kishore -- 2020")
# Run it online at https://python.jugalkishore.repl.run/