File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import random
2+
3+ def play_game ():
4+ choices = ['rock' , 'paper' , 'scissors' ]
5+
6+ user_score = 0
7+ bot_score = 0
8+
9+ for _ in range (3 ):
10+ user_choice = input ("Enter your choice (rock, paper, or scissors): " ).lower ()
11+ bot_choice = random .choice (choices )
12+
13+ if user_choice not in choices :
14+ print ("Invalid choice. Please choose from rock, paper, or scissors." )
15+ continue
16+
17+ print (f"You chose { user_choice } . Bot chose { bot_choice } ." )
18+
19+ if user_choice == bot_choice :
20+ print ("It's a tie!" )
21+ elif (user_choice == 'rock' and bot_choice == 'scissors' ) or (user_choice == 'paper' and bot_choice == 'rock' ) or (user_choice == 'scissors' and bot_choice == 'paper' ):
22+ print ("You win this round!" )
23+ user_score += 1
24+ else :
25+ print ("Bot wins this round!" )
26+ bot_score += 1
27+
28+ if user_score > bot_score :
29+ print ("You win the game!" )
30+ elif user_score < bot_score :
31+ print ("Bot wins the game!" )
32+ else :
33+ print ("It's a tie in the game!" )
34+
35+ if __name__ == "__main__" :
36+ play_game ()
You can’t perform that action at this time.
0 commit comments