Question: Question 2 Refer to Appendix A should you need the Python documentation. (a) Scissors-Paper-Stone is a hand game played between two players where each makes


Question 2 Refer to Appendix A should you need the Python documentation. (a) Scissors-Paper-Stone is a hand game played between two players where each makes a shape choice by selecting an integer: 9 for scissors, 1 for paper, and 2 for stone. The strength of the shapes with respect to one another is based on three rules: scissors () is stronger than paper (1), paper (1) is stronger than stone (2), and stone (2) is stronger than scissors (6). If the players choose the same shape, the game ends in a draw. Otherwise, the player with the stronger shape wins. Expressing a sequence of statements based on computational logic, write a function getGameOutcome that accepts 2 integers representing the shape choices of player 1 and player 2. The function returns an integer for the game outcome: o if the game ends in a draw, 1 if player 1 wins, and 2 if player 2 wins. (10 marks) Use the function choice from the random package to implement a function chooseShapes. The Python documentation for choice is reproduced here: (6) random.choice(seq) Return a random element from the non-empty sequence seq. If seq is empty, raises IndexError chooseShapes accepts a non-empty tuple as argument such as (0, 1, 2), randomly chooses one element from the tuple twice, once for player 1 and another time for player 2, and it returns both values. Note that the values returned may be same, e.g., two same numbers 2, 2, or different, e.g., 2, 1. (5 marks) You are given a dictionary: game = {'names': ['John', 'Peter'], 'winners': [1, 0, 2, 1, 1, 2, 0, 1, 1, 6]} where names records the names of the players, and winners records the winners for each of the 10 games played, with 1 referring to player 1 (John) who won game 1, 0 referring to a game draw for game 2, and 2 referring to player 2 (Peter) who won game 3, etc. Applying data structures to store and process information, write ONE (1) or more statements to perform the following tasks: (i) Display the game summary in this format, based on the data recorded in game: Game Summary Number of games drawn: 3 Number of games John won: 5 Number of games Peter won: 2 Note that you must not hardcode data that can be extracted from game. (3 marks) (ii) A new element with key shapes and value, a tuple ('scissors, 'paper', 'stone') value is to be added into game. Add the new element into game. (2 marks) Call the function chooseshapes using the tuple (0, 1, 2). Using the new element 'shapes': ('scissors', 'paper', 'stone') you have added in Q2(c)(ii), display the choices returned in words, e.g., if choose Shapes returns 0, 2, display 'scissors and stone'. Use the returned values from chooseShapes to call the function getGameOutcome. Finally, store the result of getGameOutcome into the list for the key 'winners' in dictionary game
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
