Spaces:
Sleeping
Sleeping
File size: 1,093 Bytes
f611290 |
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 39 |
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!")
# 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!"
else:
result = "You lose!"
# Display the result
st.write(result)
# Run the app
if __name__ == "__main__":
main()
|