mystycrym's picture
Create app.py
51bd633 verified
Raw History Blame Contribute Delete
972 Bytes
import streamlit as st
import random
# Title and description
st.title("Rock, Paper, Scissors Game")
st.write("Play Rock, Paper, Scissors against the computer!")
# Game choices
choices = ["Rock", "Paper", "Scissors"]
def get_winner(user_choice, ai_choice):
if user_choice == ai_choice:
return "It's a tie!"
elif (
(user_choice == "Rock" and ai_choice == "Scissors") or
(user_choice == "Paper" and ai_choice == "Rock") or
(user_choice == "Scissors" and ai_choice == "Paper")
):
return "You win!"
else:
return "Computer wins!"
# User input
st.write("### Choose your move:")
user_choice = st.radio("", choices)
if st.button("Play!"):
# Computer choice
ai_choice = random.choice(choices)
# Display choices
st.write(f"You chose: {user_choice}")
st.write(f"Computer chose: {ai_choice}")
# Determine winner
result = get_winner(user_choice, ai_choice)
st.write(f"### {result}")