Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Define the moves
|
| 5 |
+
moves = ["Rock", "Paper", "Scissors"]
|
| 6 |
+
|
| 7 |
+
# Function to determine the winner
|
| 8 |
+
def determine_winner(player_move, computer_move):
|
| 9 |
+
if player_move == computer_move:
|
| 10 |
+
return "It's a tie!"
|
| 11 |
+
elif (player_move == "Rock" and computer_move == "Scissors") or \
|
| 12 |
+
(player_move == "Paper" and computer_move == "Rock") or \
|
| 13 |
+
(player_move == "Scissors" and computer_move == "Paper"):
|
| 14 |
+
return "You win!"
|
| 15 |
+
else:
|
| 16 |
+
return "You lose!"
|
| 17 |
+
|
| 18 |
+
# Streamlit app
|
| 19 |
+
st.title("Rock, Paper, Scissors")
|
| 20 |
+
|
| 21 |
+
st.write("Choose your move:")
|
| 22 |
+
|
| 23 |
+
# Create three buttons
|
| 24 |
+
if st.button("Rock"):
|
| 25 |
+
player_move = "Rock"
|
| 26 |
+
elif st.button("Paper"):
|
| 27 |
+
player_move = "Paper"
|
| 28 |
+
elif st.button("Scissors"):
|
| 29 |
+
player_move = "Scissors"
|
| 30 |
+
else:
|
| 31 |
+
player_move = None
|
| 32 |
+
|
| 33 |
+
if player_move:
|
| 34 |
+
computer_move = random.choice(moves)
|
| 35 |
+
|
| 36 |
+
# Display player and computer moves
|
| 37 |
+
col1, col2 = st.columns(2)
|
| 38 |
+
with col1:
|
| 39 |
+
st.write("Your move:")
|
| 40 |
+
st.subheader(player_move)
|
| 41 |
+
with col2:
|
| 42 |
+
st.write("Computer's move:")
|
| 43 |
+
st.subheader(computer_move)
|
| 44 |
+
|
| 45 |
+
# Display result
|
| 46 |
+
result = determine_winner(player_move, computer_move)
|
| 47 |
+
st.write("Result:")
|
| 48 |
+
st.subheader(result)
|