import streamlit as st import random # Set up the app def main(): st.title("Rock, Paper, Scissors Game") st.write("Choose Rock, Paper, or Scissors and play against the computer!") # Initialize session state for points if "user_points" not in st.session_state: st.session_state.user_points = 0 if "computer_points" not in st.session_state: st.session_state.computer_points = 0 # User input user_choice = st.selectbox("Your choice:", ["Rock", "Paper", "Scissors"]) if st.button("Play!"): # Computer's random choice computer_choice = random.choice(["Rock", "Paper", "Scissors"]) # Display choices st.write(f"You chose: {user_choice}") st.write(f"Computer chose: {computer_choice}") # Determine the winner if user_choice == computer_choice: result = "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") ): result = "You win!" st.session_state.user_points += 1 else: result = "You lose!" st.session_state.computer_points += 1 # Display the result st.write(result) # Display the points st.write(f"Your points: {st.session_state.user_points}") st.write(f"Computer's points: {st.session_state.computer_points}") # Run the app if __name__ == "__main__": main()