superlazycoder's picture
Update app.py
b1d7433 verified
raw
history blame
1.24 kB
import streamlit as st
import random
# Define the moves
moves = ["Rock", "Paper", "Scissors"]
# Function to determine the winner
def determine_winner(player_move, computer_move):
if player_move == computer_move:
return "It's a tie!"
elif (player_move == "Rock" and computer_move == "Scissors") or \
(player_move == "Paper" and computer_move == "Rock") or \
(player_move == "Scissors" and computer_move == "Paper"):
return "You win!"
else:
return "You lose!"
# Streamlit app
st.title("Rock, Paper, Scissors")
st.write("Choose your move:")
# Create three buttons
if st.button("Rock"):
player_move = "Rock"
elif st.button("Paper"):
player_move = "Paper"
elif st.button("Scissors"):
player_move = "Scissors"
else:
player_move = None
if player_move:
computer_move = random.choice(moves)
# Display player and computer moves
col1, col2 = st.columns(2)
with col1:
st.write("Your move:")
st.subheader(player_move)
with col2:
st.write("Computer's move:")
st.subheader(computer_move)
# Display result
result = determine_winner(player_move, computer_move)
st.write("Result:")
st.subheader(result)