Spaces:
Sleeping
Sleeping
Create rock_paper_scissor_app.py
Browse files- rock_paper_scissor_app.py +38 -0
rock_paper_scissor_app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Set up the app
|
| 5 |
+
def main():
|
| 6 |
+
st.title("Rock, Paper, Scissors Game")
|
| 7 |
+
|
| 8 |
+
st.write("Choose Rock, Paper, or Scissors and play against the computer!")
|
| 9 |
+
|
| 10 |
+
# User input
|
| 11 |
+
user_choice = st.selectbox("Your choice:", ["Rock", "Paper", "Scissors"])
|
| 12 |
+
|
| 13 |
+
if st.button("Play!"):
|
| 14 |
+
# Computer's random choice
|
| 15 |
+
computer_choice = random.choice(["Rock", "Paper", "Scissors"])
|
| 16 |
+
|
| 17 |
+
# Display choices
|
| 18 |
+
st.write(f"You chose: {user_choice}")
|
| 19 |
+
st.write(f"Computer chose: {computer_choice}")
|
| 20 |
+
|
| 21 |
+
# Determine the winner
|
| 22 |
+
if user_choice == computer_choice:
|
| 23 |
+
result = "It's a tie!"
|
| 24 |
+
elif (
|
| 25 |
+
(user_choice == "Rock" and computer_choice == "Scissors") or
|
| 26 |
+
(user_choice == "Paper" and computer_choice == "Rock") or
|
| 27 |
+
(user_choice == "Scissors" and computer_choice == "Paper")
|
| 28 |
+
):
|
| 29 |
+
result = "You win!"
|
| 30 |
+
else:
|
| 31 |
+
result = "You lose!"
|
| 32 |
+
|
| 33 |
+
# Display the result
|
| 34 |
+
st.write(result)
|
| 35 |
+
|
| 36 |
+
# Run the app
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
main()
|