superlazycoder commited on
Commit
e32478e
·
verified ·
1 Parent(s): b1d7433

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -20,17 +20,30 @@ st.title("Rock, Paper, Scissors")
20
 
21
  st.write("Choose your move:")
22
 
23
- # Create three buttons
24
- if st.button("Rock"):
25
- player_move = "Rock"
26
- elif st.button("Paper"):
27
- player_move = "Paper"
28
- elif st.button("Scissors"):
29
- player_move = "Scissors"
30
- else:
31
- player_move = None
32
-
33
- if player_move:
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  computer_move = random.choice(moves)
35
 
36
  # Display player and computer moves
 
20
 
21
  st.write("Choose your move:")
22
 
23
+ # Create three horizontal buttons
24
+ col1, col2, col3 = st.columns(3)
25
+
26
+ with col1:
27
+ if st.button("Rock"):
28
+ player_move = "Rock"
29
+ with col2:
30
+ if st.button("Paper"):
31
+ player_move = "Paper"
32
+ with col3:
33
+ if st.button("Scissors"):
34
+ player_move = "Scissors"
35
+
36
+ # Ensure player_move is defined
37
+ if 'player_move' not in st.session_state:
38
+ st.session_state.player_move = None
39
+
40
+ # Assign player move to session state if a move is made
41
+ if 'player_move' in locals():
42
+ st.session_state.player_move = player_move
43
+
44
+ # If a move is selected, randomly choose a move for the computer and determine the result
45
+ if st.session_state.player_move:
46
+ player_move = st.session_state.player_move
47
  computer_move = random.choice(moves)
48
 
49
  # Display player and computer moves