The program is an illustration of conditional statements.
Conditional statements are used to execute instructions, if and only if certain <em>condition or conditions </em>are met.
Take for instance: <em>If b = 5, print "ab"</em>
The above print statement will only be executed, if the <em>value of b is 5</em>
The paper-rock-scissor program in Python where comments are used to explain each line is as follows,
#This imports the random module
import random
#This is used to control the repetition of the game
playagain ="T"
#The following is repeated until the user chooses not to play again
while(playagain == "T"):
#This generates a random choice for the computer
computer = random.choice(['Rock', 'Paper', 'Scissors'])
#This gets input for the player
player = input('Choose: ')
#If the player and computer choose the selection
if player == computer:
#Then, it's a tie
print('A tie - Both players chose '+player)
#If the player wins
elif (player.lower() == "Rock".lower() and computer.lower() == "Scissors".lower()) or (player.lower() == "Paper".lower() and computer.lower() == "Rock".lower()) or (player == "Scissors" and computer.lower() == "Paper".lower()):
#This prints "player won" and the reason
print('Player won! '+player +' beats '+computer)
#If otherwise,
else:
#This prints "computer won" and the reason
print('Computer won! '+computer+' beats '+player)
#This asks if the player wants to play again
playagain = input("Play again? T/F: ")
At the end of each round,
- The program displays the winner
- Or prints a tie, if there's a tie
See attachment for sample run
Read more about conditional statements at:
brainly.com/question/22078945