Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,29 @@ import streamlit as st
|
|
2 |
import random
|
3 |
|
4 |
# Title
|
5 |
-
st.title("Rock-Paper-Scissors Game")
|
6 |
|
7 |
-
# Instructions
|
8 |
-
st.
|
9 |
-
|
10 |
-
Choose your
|
|
|
|
|
|
|
|
|
|
|
11 |
""")
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# User input
|
|
|
14 |
choices = ["Rock", "Paper", "Scissors"]
|
15 |
-
user_choice = st.selectbox("
|
16 |
|
17 |
# Play the game
|
18 |
if st.button("Play"):
|
@@ -20,15 +32,36 @@ if st.button("Play"):
|
|
20 |
|
21 |
# Determine the winner
|
22 |
if user_choice == computer_choice:
|
23 |
-
result = "It's a Tie!"
|
24 |
elif (user_choice == "Rock" and computer_choice == "Scissors") or \
|
25 |
(user_choice == "Scissors" and computer_choice == "Paper") or \
|
26 |
(user_choice == "Paper" and computer_choice == "Rock"):
|
27 |
result = "You Win! 🎉"
|
|
|
28 |
else:
|
29 |
result = "You Lose! 😢"
|
|
|
30 |
|
31 |
# Display results
|
32 |
st.write(f"**Your Choice:** {user_choice}")
|
33 |
st.write(f"**Computer's Choice:** {computer_choice}")
|
34 |
st.subheader(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import random
|
3 |
|
4 |
# Title
|
5 |
+
st.title("🎮 Rock-Paper-Scissors Game 🎮")
|
6 |
|
7 |
+
# Sidebar for Instructions
|
8 |
+
st.sidebar.title("How to Play")
|
9 |
+
st.sidebar.write("""
|
10 |
+
1. Choose your move: Rock, Paper, or Scissors.
|
11 |
+
2. Click the "Play" button to see the result.
|
12 |
+
3. Earn points by beating the computer!
|
13 |
+
- Rock beats Scissors.
|
14 |
+
- Scissors beats Paper.
|
15 |
+
- Paper beats Rock.
|
16 |
""")
|
17 |
|
18 |
+
# Initialize session state for scores
|
19 |
+
if "user_score" not in st.session_state:
|
20 |
+
st.session_state.user_score = 0
|
21 |
+
if "computer_score" not in st.session_state:
|
22 |
+
st.session_state.computer_score = 0
|
23 |
+
|
24 |
# User input
|
25 |
+
st.subheader("Choose your move:")
|
26 |
choices = ["Rock", "Paper", "Scissors"]
|
27 |
+
user_choice = st.selectbox("Select your move:", choices)
|
28 |
|
29 |
# Play the game
|
30 |
if st.button("Play"):
|
|
|
32 |
|
33 |
# Determine the winner
|
34 |
if user_choice == computer_choice:
|
35 |
+
result = "It's a Tie! 🤝"
|
36 |
elif (user_choice == "Rock" and computer_choice == "Scissors") or \
|
37 |
(user_choice == "Scissors" and computer_choice == "Paper") or \
|
38 |
(user_choice == "Paper" and computer_choice == "Rock"):
|
39 |
result = "You Win! 🎉"
|
40 |
+
st.session_state.user_score += 1
|
41 |
else:
|
42 |
result = "You Lose! 😢"
|
43 |
+
st.session_state.computer_score += 1
|
44 |
|
45 |
# Display results
|
46 |
st.write(f"**Your Choice:** {user_choice}")
|
47 |
st.write(f"**Computer's Choice:** {computer_choice}")
|
48 |
st.subheader(result)
|
49 |
+
|
50 |
+
# Display Scores
|
51 |
+
st.write("---")
|
52 |
+
st.subheader("Scores")
|
53 |
+
col1, col2 = st.columns(2)
|
54 |
+
with col1:
|
55 |
+
st.write(f"**Your Score:** {st.session_state.user_score}")
|
56 |
+
with col2:
|
57 |
+
st.write(f"**Computer's Score:** {st.session_state.computer_score}")
|
58 |
+
|
59 |
+
# Reset scores
|
60 |
+
if st.button("Reset Scores"):
|
61 |
+
st.session_state.user_score = 0
|
62 |
+
st.session_state.computer_score = 0
|
63 |
+
st.success("Scores have been reset!")
|
64 |
+
|
65 |
+
# Footer
|
66 |
+
st.write("---")
|
67 |
+
st.markdown("💻 **Developed by Abdullah**")
|