MCPcopy Create free account
hub / github.com/CodeWithHarry/The-Ultimate-Python-Course / game

Function game

Chapter 9 - PS/02_problem2.py:3–20  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import random
2
3def game():
4 print("You are playing the game..")
5 score = random.randint(1, 62)
6 # Fetch the hiscore
7 with open("hiscore.txt") as f:
8 hiscore = f.read()
9 if(hiscore!=""):
10 hiscore = int(hiscore)
11 else:
12 hiscore = 0
13
14 print(f"Your score: {score}")
15 if(score>hiscore):
16 # write this hiscore to the file
17 with open("hiscore.txt", "w") as f:
18 f.write(str(score))
19
20 return score
21
22game()

Callers 1

02_problem2.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected