Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import random | |
| # Title of the app | |
| st.title("Rock, Paper, Scissors Game") | |
| # Rules and instructions | |
| st.write("Welcome to Rock, Paper, Scissors!") | |
| st.write("Choose your option below and see if you can beat the computer.") | |
| st.write("Rules:") | |
| st.write("- Rock beats Scissors") | |
| st.write("- Scissors beats Paper") | |
| st.write("- Paper beats Rock") | |
| # Options | |
| options = ["Rock", "Paper", "Scissors"] | |
| # User input | |
| user_choice = st.radio("Select your choice:", options) | |
| # Button to play | |
| if st.button("Play"): | |
| # Computer's random choice | |
| computer_choice = random.choice(options) | |
| # Display choices | |
| st.write(f"You chose: **{user_choice}**") | |
| st.write(f"The computer chose: **{computer_choice}**") | |
| # Determine the result | |
| if user_choice == computer_choice: | |
| result = "It's a tie!" | |
| elif (user_choice == "Rock" and computer_choice == "Scissors") or \ | |
| (user_choice == "Scissors" and computer_choice == "Paper") or \ | |
| (user_choice == "Paper" and computer_choice == "Rock"): | |
| result = "You win! π" | |
| else: | |
| result = "You lose! π’" | |
| # Display result | |
| st.write(f"**Result:** {result}") | |