-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumberguessing.py
54 lines (42 loc) · 1.83 KB
/
numberguessing.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
"""
Pick a random number from 1-100
When the user is incorrect, they give a hint such as 'the number is divisible to...', 'it's a multiple of...', 'it's odd/even'"
"""
import random
from time import sleep
def main():
while True:
answer = random.randint(1, 100)
tries = 0
hint: str
print("I picked a number from 1-100.")
while True:
guess = input("Guess my number: ")
if guess.isnumeric() and guess.isspace() == False:
if int(guess) != answer:
tries += 1
print(f"\nWRONG! It's NOT {guess}")
if (answer % 2) == 0 and (int(guess) % 2) != 0: hint = "The answer is an EVEN number."
elif (answer % 2) != 0 and (int(guess) % 2) == 0: hint = "The answer is an ODD number."
else:
if answer < int(guess): hint = f"The answer is LESS than {guess}."
else: hint = f"The answer is GREATER than {guess}."
print("Hint: ", hint ,"\n")
continue
else:
print(f"\nCORRECT! The answer is {answer}!")
print(f"It took you {tries} tries until you got it right!\n")
replay = input("Wanna play again? [y/n]: ")
if replay.lower() == "y":
print("\nAlright! Let's play again!\n")
break
else:
print("Okay, bye bye!\n")
exit()
else:
print("\nPlease input an INTEGER!\n")
break
continue
if __name__ == "__main__":
print("Number Guessing Program by Len.icon\n")
main()