umarabbas890's picture
Rename rock_paper_scissor_app.py to app.py
865b1f4 verified
raw
history blame
1.09 kB
import streamlit as st
import random
# Set up the app
def main():
st.title("Rock, Paper, Scissors Game")
st.write("Choose Rock, Paper, or Scissors and play against the computer!")
# User input
user_choice = st.selectbox("Your choice:", ["Rock", "Paper", "Scissors"])
if st.button("Play!"):
# Computer's random choice
computer_choice = random.choice(["Rock", "Paper", "Scissors"])
# Display choices
st.write(f"You chose: {user_choice}")
st.write(f"Computer chose: {computer_choice}")
# Determine the winner
if user_choice == computer_choice:
result = "It's a tie!"
elif (
(user_choice == "Rock" and computer_choice == "Scissors") or
(user_choice == "Paper" and computer_choice == "Rock") or
(user_choice == "Scissors" and computer_choice == "Paper")
):
result = "You win!"
else:
result = "You lose!"
# Display the result
st.write(result)
# Run the app
if __name__ == "__main__":
main()