Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Page config (wide layout + nicer title)
|
| 5 |
+
st.set_page_config(page_title="๐ฎ Rock Paper Scissors", layout="wide")
|
| 6 |
+
|
| 7 |
+
# Custom CSS for buttons
|
| 8 |
+
st.markdown("""
|
| 9 |
+
<style>
|
| 10 |
+
.btn-img {
|
| 11 |
+
background:none;
|
| 12 |
+
border:none;
|
| 13 |
+
padding: 10px;
|
| 14 |
+
cursor: pointer;
|
| 15 |
+
}
|
| 16 |
+
.btn-img:hover {
|
| 17 |
+
transform: scale(1.2);
|
| 18 |
+
transition-duration: 0.2s;
|
| 19 |
+
}
|
| 20 |
+
</style>
|
| 21 |
+
""", unsafe_allow_html=True)
|
| 22 |
+
|
| 23 |
+
st.title("๐ชจ๐โ๏ธ Rock Paper Scissors")
|
| 24 |
+
|
| 25 |
+
# Show choices as images (you can replace URLs with your own hosted images)
|
| 26 |
+
col1, col2, col3 = st.columns(3)
|
| 27 |
+
|
| 28 |
+
with col1:
|
| 29 |
+
if st.button("๐ชจ Rock", key="rock"):
|
| 30 |
+
user_choice = "Rock"
|
| 31 |
+
with col2:
|
| 32 |
+
if st.button("๐ Paper", key="paper"):
|
| 33 |
+
user_choice = "Paper"
|
| 34 |
+
with col3:
|
| 35 |
+
if st.button("โ๏ธ Scissors", key="scissors"):
|
| 36 |
+
user_choice = "Scissors"
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
user_choice
|
| 40 |
+
except NameError:
|
| 41 |
+
st.write("๐ **Choose Rock, Paper, or Scissors to start!**")
|
| 42 |
+
else:
|
| 43 |
+
# Computer move
|
| 44 |
+
computer_choice = random.choice(["Rock", "Paper", "Scissors"])
|
| 45 |
+
|
| 46 |
+
# Display choices
|
| 47 |
+
st.markdown(f"๐ก **You chose:** {user_choice}")
|
| 48 |
+
st.markdown(f"๐ค **Computer chose:** {computer_choice}")
|
| 49 |
+
|
| 50 |
+
# Result logic
|
| 51 |
+
if user_choice == computer_choice:
|
| 52 |
+
st.info("๐ค It's a tie!")
|
| 53 |
+
elif (
|
| 54 |
+
(user_choice == "Rock" and computer_choice == "Scissors") or
|
| 55 |
+
(user_choice == "Paper" and computer_choice == "Rock") or
|
| 56 |
+
(user_choice == "Scissors" and computer_choice == "Paper")
|
| 57 |
+
):
|
| 58 |
+
st.balloons()
|
| 59 |
+
st.success("๐ You win!")
|
| 60 |
+
else:
|
| 61 |
+
st.error("๐ข You lose!")
|