Homework Help Question & Answers
5.12 A5 Program Do you want to play. a. game? The Big Bang Theory fans may…
5.12 A5 Program Do you want to play. a. game? The Big Bang Theory fans may recognize Rock Paper Scissors Lizard Spock as a game of chance that expands on the standard Rock Paper Scissors game. It introduces two new hand signs and several more rules.
The rules: • Scissors cuts Paper • Paper covers Rock • Rock crushes Lizard • Lizard poisons Spock • Spock smashes Scissors • Scissors decapitates Lizard • Lizard eats Paper • Paper disproves Spock • Spock vaporizes Rock • Rock crushes Scissors So, the player choosing the item on the left wins and the player choosing the item on the right loses. It is a draw if both players choose the same item. In this assignment you will write a program to implement the game so a human player competes against a computer player. • The program should ask the human player to enter one of the five options. • The program should randomly select one of the five options for the computer player. • The options should be lowercase. • The program should determine the outcome win, lose, draw) from the human player’s perspective and print the result on a line with the human player’s choice, the outcome, and the computer player’s choice in that order. Here are a few examples with an input of spock. rock, paper, scissors, lizard, or spock? spock win rock rock, paper, scissors, lizard, or spock? spock draw spock rock, paper, scissors, lizard, or spock? spock lose lizard To help you get started we have defined some functions to decompose the problem. You only need to complete the human player and outcome functions. We used the seed and choice functions from the random module in this assignment for the computer player. The grading will test the outcome function and the output. You should not modify the function definitions when you complete the function body.
LAB ACTIVITY 5.12.1: A5 Program 0/10 main.py Load default template. from random import choice, seed choices = [‘rock’, ‘paper’, ‘scissors’, ‘lizard’, ‘spook’] def outcome (player1, player2): if player1==choices[2] and player2==choices[1]: return ‘win’ elif player1==choices[2] and player2==choices[0]: return ‘win’ elif player1==choices[0] and player2==choices[2]: return ‘win’ elif player1==choices[3] and player2==choices[4]: return ‘win’ elif player1==choices[2] and player2==choices[3]: return ‘win’ elif player1==choices[3] and player2==choices[1]: return ‘win’ elif player1==choices[1] and player2==choices[4]: return ‘win’ elif player1==choices[4] and player2==choices[0]: return ‘win’ elif player1==choices[3] and player2==choices[1]: return ‘win’ elif player1==choices[0] and player2==choices[2]: return ‘win’ elif player1==player2: return ‘draw’ else: return ‘lose def human_player(): while True: choose = input(‘rock, paper, scissors, lizards, or spock?n’) if choose. lower() in choices: return choose.lower() else: print(‘Incorrect selection.’) 50 def computer_player(): return choice (choices)
54 def main(): human=human_player() computer =computer_player() print(human, outcome (human, computer), computer) 59 if __name__ == ‘__main__’: seed(42)
Add a comment