Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Title of the app
|
| 5 |
+
st.title("Rock, Paper, Scissors Game")
|
| 6 |
+
|
| 7 |
+
# Rules and instructions
|
| 8 |
+
st.write("Welcome to Rock, Paper, Scissors!")
|
| 9 |
+
st.write("Choose your option below and see if you can beat the computer.")
|
| 10 |
+
st.write("Rules:")
|
| 11 |
+
st.write("- Rock beats Scissors")
|
| 12 |
+
st.write("- Scissors beats Paper")
|
| 13 |
+
st.write("- Paper beats Rock")
|
| 14 |
+
|
| 15 |
+
# Options
|
| 16 |
+
options = ["Rock", "Paper", "Scissors"]
|
| 17 |
+
|
| 18 |
+
# User input
|
| 19 |
+
user_choice = st.radio("Select your choice:", options)
|
| 20 |
+
|
| 21 |
+
# Button to play
|
| 22 |
+
if st.button("Play"):
|
| 23 |
+
# Computer's random choice
|
| 24 |
+
computer_choice = random.choice(options)
|
| 25 |
+
|
| 26 |
+
# Display choices
|
| 27 |
+
st.write(f"You chose: **{user_choice}**")
|
| 28 |
+
st.write(f"The computer chose: **{computer_choice}**")
|
| 29 |
+
|
| 30 |
+
# Determine the result
|
| 31 |
+
if user_choice == computer_choice:
|
| 32 |
+
result = "It's a tie!"
|
| 33 |
+
elif (user_choice == "Rock" and computer_choice == "Scissors") or \
|
| 34 |
+
(user_choice == "Scissors" and computer_choice == "Paper") or \
|
| 35 |
+
(user_choice == "Paper" and computer_choice == "Rock"):
|
| 36 |
+
result = "You win! 🎉"
|
| 37 |
+
else:
|
| 38 |
+
result = "You lose! 😢"
|
| 39 |
+
|
| 40 |
+
# Display result
|
| 41 |
+
st.write(f"**Result:** {result}")
|
| 42 |
+
|