-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGuessTheNumber.py
More file actions
35 lines (29 loc) · 871 Bytes
/
GuessTheNumber.py
File metadata and controls
35 lines (29 loc) · 871 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
import random
maxNumber = 100
correctNumber = random.randint(1, maxNumber)
hasGuessedCorrectly = False
guesses = 0
maxGuesses = int(maxNumber / 15)
def isnumber(x):
try:
int(x)
return True
except ValueError:
return False
while not hasGuessedCorrectly and guesses < maxGuesses:
guess = input("What's the number? ")
if not isnumber(guess):
print("That's not a number, nerd")
continue
if int(guess) < correctNumber:
print("Too low")
if int(guess) > correctNumber:
print("Too high")
if int(guess) is correctNumber:
hasGuessedCorrectly = True
else:
guesses += 1
if guesses is not maxGuesses:
print("Correct! The number was " + str(correctNumber))
else:
print("You're not very smart. The number was " + str(correctNumber) + ". Better luck next time, loser.")