forked from adarshpandey10t/Hacktoberfestmine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThePerfectGuess.py
More file actions
30 lines (22 loc) · 767 Bytes
/
ThePerfectGuess.py
File metadata and controls
30 lines (22 loc) · 767 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
import random
randNumber = random.randint(1,100)
# print(randNumber)
guesses = 0
userGuess = None
while (userGuess != randNumber):
userGuess = int(input("Enter your guess: "))
guesses += 1
if(userGuess == randNumber):
print("you guessed it right!")
else:
if(userGuess > randNumber):
print("You guessed it wrong! Enter a smaller number")
else:
print("You guessed it wrong! Enter a larger number")
print(f"you guessed the number in {guesses} guesses")
with open("python self/project/hiscore.txt", "r") as f:
hiscore = int(f.read())
if(guesses < hiscore):
print("you have just broken the highscore!")
with open("python self/project/hiscore.txt", "w") as f:
f.write(str(guesses))