File size: 1,572 Bytes
f611290
 
 
 
 
 
 
 
 
f0a47f6
 
 
 
 
 
f611290
 
 
 
 
 
 
 
 
 
 
 
8a2df6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
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()