()
| 1 | import random |
| 2 | |
| 3 | def 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 | |
| 22 | game() |