Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Title of the app
|
| 5 |
+
st.title("Rock, Paper, Scissors Game")
|
| 6 |
+
|
| 7 |
+
# Game instructions
|
| 8 |
+
st.write("""
|
| 9 |
+
Choose Rock, Paper, or Scissors to play against the computer.
|
| 10 |
+
""")
|
| 11 |
+
|
| 12 |
+
# Player's choice
|
| 13 |
+
options = ['Rock', 'Paper', 'Scissors']
|
| 14 |
+
player_choice = st.selectbox("Choose your move:", options)
|
| 15 |
+
|
| 16 |
+
# Button to play the game
|
| 17 |
+
if st.button('Play'):
|
| 18 |
+
# Computer's random choice
|
| 19 |
+
computer_choice = random.choice(options)
|
| 20 |
+
|
| 21 |
+
# Display choices
|
| 22 |
+
st.write(f"Your choice: {player_choice}")
|
| 23 |
+
st.write(f"Computer's choice: {computer_choice}")
|
| 24 |
+
|
| 25 |
+
# Determine the result
|
| 26 |
+
if player_choice == computer_choice:
|
| 27 |
+
result = "It's a tie!"
|
| 28 |
+
elif (player_choice == 'Rock' and computer_choice == 'Scissors') or \
|
| 29 |
+
(player_choice == 'Paper' and computer_choice == 'Rock') or \
|
| 30 |
+
(player_choice == 'Scissors' and computer_choice == 'Paper'):
|
| 31 |
+
result = "You win!"
|
| 32 |
+
else:
|
| 33 |
+
result = "You lose!"
|
| 34 |
+
|
| 35 |
+
# Display the result
|
| 36 |
+
st.write(result)
|