hareshchander commited on
Commit
c3235f9
·
verified ·
1 Parent(s): 4a7e4fd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+
4
+ # Title of the app
5
+ st.title("Rock-Paper-Scissors Game")
6
+
7
+ # Instructions
8
+ st.write("Choose Rock, Paper, or Scissors and play against the computer!")
9
+
10
+ # Options for the game
11
+ choices = ["Rock", "Paper", "Scissors"]
12
+
13
+ # User's choice
14
+ user_choice = st.selectbox("Make your choice:", choices)
15
+
16
+ # Button to submit the choice
17
+ if st.button("Play"):
18
+ # Computer's random choice
19
+ computer_choice = random.choice(choices)
20
+
21
+ # Display both choices
22
+ st.write(f"**You chose:** {user_choice}")
23
+ st.write(f"**Computer chose:** {computer_choice}")
24
+
25
+ # Determine the winner
26
+ if user_choice == computer_choice:
27
+ st.info("It's a tie!")
28
+ elif (
29
+ (user_choice == "Rock" and computer_choice == "Scissors") or
30
+ (user_choice == "Paper" and computer_choice == "Rock") or
31
+ (user_choice == "Scissors" and computer_choice == "Paper")
32
+ ):
33
+ st.success("You win! 🎉")
34
+ else:
35
+ st.error("You lose! 😢")
36
+
37
+ # Add an image for fun (optional)
38
+ st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Rock-paper-scissors.svg/1920px-Rock-paper-scissors.svg.png", caption="Rock-Paper-Scissors", width=400)