shehzaduet commited on
Commit
b5a9731
Β·
verified Β·
1 Parent(s): 661bbe9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import random
3
 
@@ -7,16 +8,22 @@ st.set_page_config(page_title="Rock Paper Scissors", page_icon="βœ‚οΈ", layout=
7
  st.title("Rock Paper Scissors Game βœŠπŸ–οΈβœŒοΈ")
8
  st.markdown("""
9
  Play a game of **Rock-Paper-Scissors** against the computer!
10
- Choose your move below, and see if you can beat the machine.
11
  """)
12
 
 
 
 
 
 
 
13
  # Choices for the game
14
  choices = ["Rock", "Paper", "Scissors"]
15
 
16
  # Mapping choices to emojis
17
  emoji_map = {"Rock": "✊", "Paper": "πŸ–οΈ", "Scissors": "✌️"}
18
 
19
- # Function to determine the winner
20
  def determine_winner(user_choice, computer_choice):
21
  if user_choice == computer_choice:
22
  return "It's a tie! 🀝"
@@ -25,14 +32,21 @@ def determine_winner(user_choice, computer_choice):
25
  (user_choice == "Paper" and computer_choice == "Rock") or
26
  (user_choice == "Scissors" and computer_choice == "Paper")
27
  ):
 
28
  return "You win! πŸŽ‰"
29
  else:
 
30
  return "You lose! 😒"
31
 
 
 
 
 
 
32
  # User's choice
33
  user_choice = st.radio("Choose your move:", choices)
34
 
35
- # Generate computer's choice
36
  if st.button("Play"):
37
  computer_choice = random.choice(choices)
38
 
@@ -43,3 +57,9 @@ if st.button("Play"):
43
  # Determine the winner
44
  result = determine_winner(user_choice, computer_choice)
45
  st.subheader(result)
 
 
 
 
 
 
 
1
+
2
  import streamlit as st
3
  import random
4
 
 
8
  st.title("Rock Paper Scissors Game βœŠπŸ–οΈβœŒοΈ")
9
  st.markdown("""
10
  Play a game of **Rock-Paper-Scissors** against the computer!
11
+ Choose your move below, and see if you can outscore the machine.
12
  """)
13
 
14
+ # Initialize session state variables for scores
15
+ if 'user_score' not in st.session_state:
16
+ st.session_state['user_score'] = 0
17
+ if 'computer_score' not in st.session_state:
18
+ st.session_state['computer_score'] = 0
19
+
20
  # Choices for the game
21
  choices = ["Rock", "Paper", "Scissors"]
22
 
23
  # Mapping choices to emojis
24
  emoji_map = {"Rock": "✊", "Paper": "πŸ–οΈ", "Scissors": "✌️"}
25
 
26
+ # Function to determine the winner and update scores
27
  def determine_winner(user_choice, computer_choice):
28
  if user_choice == computer_choice:
29
  return "It's a tie! 🀝"
 
32
  (user_choice == "Paper" and computer_choice == "Rock") or
33
  (user_choice == "Scissors" and computer_choice == "Paper")
34
  ):
35
+ st.session_state['user_score'] += 1
36
  return "You win! πŸŽ‰"
37
  else:
38
+ st.session_state['computer_score'] += 1
39
  return "You lose! 😒"
40
 
41
+ # Display current scores
42
+ st.sidebar.header("Scores")
43
+ st.sidebar.write(f"**Your Score:** {st.session_state['user_score']}")
44
+ st.sidebar.write(f"**Computer's Score:** {st.session_state['computer_score']}")
45
+
46
  # User's choice
47
  user_choice = st.radio("Choose your move:", choices)
48
 
49
+ # Generate computer's choice and play the game
50
  if st.button("Play"):
51
  computer_choice = random.choice(choices)
52
 
 
57
  # Determine the winner
58
  result = determine_winner(user_choice, computer_choice)
59
  st.subheader(result)
60
+
61
+ # Reset Scores Button
62
+ if st.sidebar.button("Reset Scores"):
63
+ st.session_state['user_score'] = 0
64
+ st.session_state['computer_score'] = 0
65
+ st.sidebar.success("Scores have been reset!")