Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions rock_paper_scissors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
user_wins = 0
computer_wins = 0

# ----- LOADING SCORE -----
try:
with open("score.txt", "r") as f:
data = f.read().strip()
if data:
user_wins, computer_wins = map(int, data.split(","))
else:
user_wins = 0
computer_wins = 0
except:
user_wins = 0
computer_wins = 0


options = ["rock", "paper", "scissors"]

while True:
Expand Down Expand Up @@ -33,6 +47,9 @@
else:
print("You lost!")
computer_wins += 1
# ----- SAVE SCORE -----
with open("score.txt", "w") as f:
f.write(f"{user_wins},{computer_wins}")

print("You won", user_wins, "times.")
print("The computer won", computer_wins, "times.")
Expand Down