Abdullah-Basar
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
|
4 |
+
# Title
|
5 |
+
st.title("Rock-Paper-Scissors Game")
|
6 |
+
|
7 |
+
# Instructions
|
8 |
+
st.write("""
|
9 |
+
Welcome to the Rock-Paper-Scissors game!
|
10 |
+
Choose your option and see if you can beat the computer.
|
11 |
+
""")
|
12 |
+
|
13 |
+
# User input
|
14 |
+
choices = ["Rock", "Paper", "Scissors"]
|
15 |
+
user_choice = st.selectbox("Choose your move:", choices)
|
16 |
+
|
17 |
+
# Play the game
|
18 |
+
if st.button("Play"):
|
19 |
+
computer_choice = random.choice(choices)
|
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)
|