Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,19 @@ import random
|
|
| 3 |
|
| 4 |
# Title and description
|
| 5 |
st.title("Rock, Paper, Scissors Game")
|
| 6 |
-
st.write("Play a simple game of Rock, Paper, Scissors against the computer!")
|
| 7 |
|
| 8 |
# Options
|
| 9 |
choices = ["Rock", "Paper", "Scissors"]
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# User's choice
|
| 12 |
user_choice = st.selectbox("Choose your option:", choices)
|
| 13 |
|
|
@@ -19,14 +27,17 @@ def play_game():
|
|
| 19 |
# Determine the winner
|
| 20 |
if user_choice == computer_choice:
|
| 21 |
result = "It's a draw!"
|
|
|
|
| 22 |
elif (
|
| 23 |
(user_choice == "Rock" and computer_choice == "Scissors") or
|
| 24 |
(user_choice == "Paper" and computer_choice == "Rock") or
|
| 25 |
(user_choice == "Scissors" and computer_choice == "Paper")
|
| 26 |
):
|
| 27 |
result = "You win!"
|
|
|
|
| 28 |
else:
|
| 29 |
result = "Computer wins!"
|
|
|
|
| 30 |
|
| 31 |
return computer_choice, result
|
| 32 |
|
|
@@ -37,3 +48,10 @@ if st.button("Play"):
|
|
| 37 |
st.write(f"You chose: {user_choice}")
|
| 38 |
st.write(f"Computer chose: {computer_choice}")
|
| 39 |
st.success(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Title and description
|
| 5 |
st.title("Rock, Paper, Scissors Game")
|
| 6 |
+
st.write("Play a simple game of Rock, Paper, Scissors against the computer! Track your score as you play.")
|
| 7 |
|
| 8 |
# Options
|
| 9 |
choices = ["Rock", "Paper", "Scissors"]
|
| 10 |
|
| 11 |
+
# Initialize session state for scores
|
| 12 |
+
if 'user_score' not in st.session_state:
|
| 13 |
+
st.session_state.user_score = 0
|
| 14 |
+
if 'computer_score' not in st.session_state:
|
| 15 |
+
st.session_state.computer_score = 0
|
| 16 |
+
if 'draws' not in st.session_state:
|
| 17 |
+
st.session_state.draws = 0
|
| 18 |
+
|
| 19 |
# User's choice
|
| 20 |
user_choice = st.selectbox("Choose your option:", choices)
|
| 21 |
|
|
|
|
| 27 |
# Determine the winner
|
| 28 |
if user_choice == computer_choice:
|
| 29 |
result = "It's a draw!"
|
| 30 |
+
st.session_state.draws += 1
|
| 31 |
elif (
|
| 32 |
(user_choice == "Rock" and computer_choice == "Scissors") or
|
| 33 |
(user_choice == "Paper" and computer_choice == "Rock") or
|
| 34 |
(user_choice == "Scissors" and computer_choice == "Paper")
|
| 35 |
):
|
| 36 |
result = "You win!"
|
| 37 |
+
st.session_state.user_score += 1
|
| 38 |
else:
|
| 39 |
result = "Computer wins!"
|
| 40 |
+
st.session_state.computer_score += 1
|
| 41 |
|
| 42 |
return computer_choice, result
|
| 43 |
|
|
|
|
| 48 |
st.write(f"You chose: {user_choice}")
|
| 49 |
st.write(f"Computer chose: {computer_choice}")
|
| 50 |
st.success(result)
|
| 51 |
+
|
| 52 |
+
# Display scores
|
| 53 |
+
st.write("### Scores:")
|
| 54 |
+
st.write(f"Your Score: {st.session_state.user_score}")
|
| 55 |
+
st.write(f"Computer Score: {st.session_state.computer_score}")
|
| 56 |
+
st.write(f"Draws: {st.session_state.draws}")
|
| 57 |
+
|