File size: 851 Bytes
dbd1732 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import streamlit as st
import random
# Define the choices
choices = ['Rock', 'Paper', 'Scissors']
# Function to determine the 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 'AI wins!'
# Streamlit app layout
st.title('Rock, Paper, Scissors Game')
st.write('Choose your move:')
# User selection
user_choice = st.selectbox('Your choice:', choices)
# AI selection
if st.button('Play'):
ai_choice = random.choice(choices)
st.write(f'AI chose: {ai_choice}')
result = determine_winner(user_choice, ai_choice)
st.write(result)
|