-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_handling.py
More file actions
25 lines (22 loc) · 923 Bytes
/
Copy pathfile_handling.py
File metadata and controls
25 lines (22 loc) · 923 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
import os
import random
def load_words_from_file(filename="word_list.txt"):
try:
with open(filename, "r") as f:
words = [line.strip() for line in f if line.strip()]
return random.choice(words)
except FileNotFoundError:
print("⚠️ word_list.txt not found. Using fallback words.")
return random.choice(["default", "python", "hangman"])
def save_to_leaderboard(username, result, duration):
with open("leaderboard.txt", "a") as file:
file.write(f"{username},{result},{duration:.2f}s\n")
def view_leaderboard():
if not os.path.exists("leaderboard.txt"):
print("🏆 No leaderboard data yet.")
return
print("\n🏆 Leaderboard:")
with open("leaderboard.txt", "r") as file:
for line in file:
name, result, duration = line.strip().split(",")
print(f"👤 {name} | Result: {result} | Time: {duration}")