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)]

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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)]

Expert Solution
Step 1

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.

Step 2

SCREENSHOT OF THE PROGRAM:

Computer Science homework question answer, step 2, image 1

Computer Science homework question answer, step 2, image 2

Computer Science homework question answer, step 2, image 3

Computer Science homework question answer, step 2, image 4

Computer Science homework question answer, step 2, image 5

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education