Spaces:
Runtime error
Runtime error
File size: 972 Bytes
51bd633 | 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 32 33 34 35 36 37 38 | 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}")
|