Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import random | |
| # Function to determine the winner | |
| def get_winner(user_choice, computer_choice): | |
| if user_choice == computer_choice: | |
| return "It's a Tie!" | |
| elif (user_choice == "Rock" and computer_choice == "Scissors") or \ | |
| (user_choice == "Paper" and computer_choice == "Rock") or \ | |
| (user_choice == "Scissors" and computer_choice == "Paper"): | |
| return "You Win! π" | |
| else: | |
| return "You Lose! π" | |
| # Streamlit App | |
| st.title("Rock-Paper-Scissors Game βοΈπβ") | |
| st.subheader("Play a quick game and test your luck!") | |
| # User's choice | |
| user_choice = st.radio("Choose your move:", ["Rock", "Paper", "Scissors"], index=0) | |
| # Generate computer's choice | |
| computer_choice = random.choice(["Rock", "Paper", "Scissors"]) | |
| # Play button | |
| if st.button("Play!"): | |
| result = get_winner(user_choice, computer_choice) | |
| # Display results | |
| st.write(f"**Your choice:** {user_choice}") | |
| st.write(f"**Computer's choice:** {computer_choice}") | |
| st.subheader(result) | |
| st.write("Have fun! Refresh the page to play again.") | |