Create a game of rock paper scissors with an AI opponent
To upload files, please first save the app
import streamlit as st
import random
st.title("Rock, Paper, Scissors Game")
# Define options
options = ["Rock", "Paper", "Scissors"]
# Function to determine winner
def determine_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 "You lose!"
# User input
user_choice = st.selectbox("Choose your weapon:", options)
if st.button("Play"):
ai_choice = random.choice(options)
st.write(f"AI chose: {ai_choice}")
result = determine_winner(user_choice, ai_choice)
st.write(result)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?