We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 26462bf + 04d39dc commit 8543888Copy full SHA for 8543888
1 file changed
games/Rock-Paper-Scissor/Rock-Paper-Scissor.py
@@ -1,8 +1,8 @@
1
import random
2
-import os
3
from pathlib import Path
4
5
RESULTS_FILE = Path(__file__).parent / "game_results.txt"
+RESULTS_FILE.parent.mkdir(parents=True, exist_ok=True)
6
7
8
def parse_results():
@@ -210,11 +210,11 @@ def main():
210
f"(User-Computer), Rounds: {rounds_played}\n"
211
)
212
try:
213
- with open(RESULTS_FILE, "a", encoding="utf-8") as f:
+ with RESULTS_FILE.open("a", encoding="utf-8") as f:
214
f.write(result_string)
215
print("Game results saved successfully.")
216
- except IOError:
217
- print("Error: Could not save game results to file.")
+ except OSError as e:
+ print(f"Error: Could not save game results: {e}")
218
break
219
220
0 commit comments