Can you annotate this code. from random import randint t = ["R", "P", "S"] computer = t[randint(0,2)] player = False com=0 pl=0 while player == False: print("Computer's choice is",computer) player = input("Enter R for Rock, P for Paper and S for Scissors: ") if player == computer: print("Its a tie") elif player == "R": if computer == "P": print("OOPS you loose", computer, "covers", player) com+=1 else: print(" Hurray! You win!", player, "smashes", computer) pl+=1 elif player == "P": if computer == "S": print("OOPS you loose", computer, "cut", player) com+=1 else: print(" Hurray! ", player, "covers", computer) pl+=1 elif player == "S": if computer == "R": print("OOPS you loose", computer, "smashes", player) com+=1 else: print(" Hurray! You win!", player, "cut", computer) pl+=1 else: print("Invalid input , Please Enter a valid input") print("player: ",pl) print("computer: ",com) player = False computer = t[randint(0,2)]
Can you annotate this code.
from random import randint
t = ["R", "P", "S"]
computer = t[randint(0,2)]
player = False
com=0
pl=0
while player == False:
print("Computer's choice is",computer)
player = input("Enter R for Rock, P for Paper and S for Scissors: ")
if player == computer:
print("Its a tie")
elif player == "R":
if computer == "P":
print("OOPS you loose", computer, "covers", player)
com+=1
else:
print(" Hurray! You win!", player, "smashes", computer)
pl+=1
elif player == "P":
if computer == "S":
print("OOPS you loose", computer, "cut", player)
com+=1
else:
print(" Hurray! ", player, "covers", computer)
pl+=1
elif player == "S":
if computer == "R":
print("OOPS you loose", computer, "smashes", player)
com+=1
else:
print(" Hurray! You win!", player, "cut", computer)
pl+=1
else:
print("Invalid input , Please Enter a valid input")
print("player: ",pl)
print("computer: ",com)
player = False
computer = t[randint(0,2)]

PROGRAM:
#Importing randint from random header file
from random import randint
#Delcaring list
t = ["R", "P", "S"]
#Generating random value for computer
computer = t[randint(0,2)]
#Setting player value as false
player = False
#Initializing computer score
com=0
#Initializing player score
pl=0
#Looping
while player == False:
#Printing the computer choice
print("Computer's choice is",computer)
#Getting input from the player
player = input("Enter R for Rock, P for Paper and S for Scissors: ")
#Checking results of computer and player
if player == computer:
#If both choosing same value
#Then the result will be tie
print("Its a tie")
#If player chooses R
elif player == "R":
#But the computer chooses P means
if computer == "P":
#Player loss, computer wins
print("OOPS you loose", computer, "covers", player)
#Incrementing computer score
com+=1
else:
#otherwise user win
print(" Hurray! You win!", player, "smashes", computer)
#Incrementing player score
pl+=1
#If the player chooses P
elif player == "P":
#But the computer chooses S
if computer == "S":
#Then Player loss, computer wins
print("OOPS you loose", computer, "cut", player)
#Incrementing computer score
com+=1
else:
#Otherwise player wins, computer lose
print(" Hurray! ", player, "covers", computer)
#Increment the player score
pl+=1
#If player chooses S
elif player == "S":
#If the computer chooses R
if computer == "R":
#Player lose the game, computer wins
print("OOPS you loose", computer, "smashes", player)
#Increment computer score
com+=1
else:
#Otherwise player wins
print(" Hurray! You win!", player, "cut", computer)
#Increment the player score
pl+=1
#If player enters invalid character
else:
#Print the message
print("Invalid input , Please Enter a valid input")
#Printing player score
print("player: ",pl)
#Printing computer score
print("computer: ",com)
#Player set to False
player = False
computer = t[randint(0,2)]
Note: Since you are not providing proper indentation, we are aligning the program based on program requirements.
SCREENSHOT OF THE PROGRAM:
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 6 images









