File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import random
2+
3+
4+ def getUserInput ():
5+ player = 'blank'
6+ while player .lower () != 'r' and player .lower () != 'p' and player .lower () != 's' :
7+ player = input ("\n \n Enter your valid choice from R,P or S: " ).lower ()
8+ return player
9+
10+
11+ def getSystemInput ():
12+ lst = ['r' , 'p' , 's' ]
13+ bot = random .choice (lst )
14+ return bot
15+
16+
17+ def checkWinner (player , bot ):
18+ if player == bot : # If both player and bot choose the same
19+ return 'draw'
20+ elif player == 'r' and bot == 'p' :
21+ return 'bot'
22+ elif player == 'r' and bot == 's' :
23+ return 'player'
24+ elif player == 'p' and bot == 'r' :
25+ return 'player'
26+ elif player == 'p' and bot == 's' :
27+ return 'bot'
28+ elif player == 's' and bot == 'r' :
29+ return 'bot'
30+ elif player == 's' and bot == 'p' :
31+ return 'player'
32+
33+
34+ def rockPaperScissor ():
35+ resume = 'y'
36+ player_score = 0
37+ bot_score = 0
38+ while resume .lower () == 'y' :
39+ ply = getUserInput ()
40+ bt = getSystemInput ()
41+ print ('Bot Entered - ' , bt )
42+ print ('You Entered - ' , ply )
43+ winner = checkWinner (ply , bt )
44+ print ('Winner is - ' , winner )
45+ if winner == 'player' :
46+ player_score += 1
47+ elif winner == 'bot' :
48+ bot_score += 1
49+ print ("\n \n ------ScoreCard------" )
50+ print ("Player:" , player_score )
51+ print ("Bot:" , bot_score )
52+ resume = input ("\n \n DO YOU WANT TO CONTINUE THE GAME!? Press y : " )
53+
54+
55+ rockPaperScissor ()
You can’t perform that action at this time.
0 commit comments