5/5 – (3 votes)
Write a program that utilizes functions to simulate a game of rock-paper-scissors Continue practicing with loops Continue practicing with variable declaration and assignmentSetup Create a new .py file in your desired directory, and rename the file When you name the code, use the following naming conventionITP115_l#_lastname_firstname (replace # with this lab number) Your new file must begin with comments in the following format (replace the name and email with your actual information):# Name# ITP 115, Spring 2017# Lab practical L^ (replace ^ with this lab number)# USC emailDescription/Rules of Program Write a program that allows the user to play Rock, Paper, Scissors against the computer. When the program begins, you randomly choose a number from 0 to 2, which will represent the computers choice with 0 for rock, 1 for paper, or 2 for scissors. The user then enters his/her choice of 0 for rock, 1 for paper, or 2 for scissors. A winner is selected based on the following rules:o Rock smashes scissors (If one player chooses rock and the other choosesscissors, then the player who chooses rock wins).o Scissors cut paper (If one player chooses scissors and the other chooses paper, then the player who chooses scissors wins).o Paper covers rock (If one player chooses paper and the other chooses rock, then the player who chooses paper wins).o If both players make the same choice, then it is a tie. ITP 115 Programming in Python p. 2 of 4 The game continues as long as the player wants to continue. When the player decides to exit the program, display the score results (how many times the player won and how many times the computer won).Requirements main() Input: none Output: none Create a while loop that runs as long as the user wants to continue the game In the loop, you should display the menu, get the computers choice, get the players choice, and play a round (see who won) Since playRound will return the result of who won the game, you will alsoneed to keep track of the score This means keeping a counter for how many times the computer won, a counter for how many times the player won, and a counter for how many times they tied These counters should be local variables to main and should be changed based on the return value (output) of playRound Call continueGame to ask the user if they want to continue, and use their response to control the while loop When the user exits, display all the final results (i.e. number of ties, number ofplayer wins, and number of computer wins) In addition to main, your program should have the following functions displayMenu() Input: none Output: none displays the game rules to the user getComputerChoice() Input: none Output: integer that is randomly chosen, a number between 0 to 2 getPlayerChoice() Input: none Output: integer represents the choice Asks the user for their choice: 0 for rock, 1 for paper, or 2 for scissors. playRound(computerChoice, playerChoice)ITP 115 Programming in Python p. 3 of 4 Input: two integersone representing the computers choice (0, 1, or2) and the other representing the players choice (0, 1, or 2) Output: integer return -1 if the computer won the round return 1 if the player won the round return 0 if there was a tie This method contains the game logic so it simulates the game and determines a winner. Use the logic described above to see who should win a round continueGame() Input: none Output: boolean Ask the user if they want to continue (Y/N), and then return True or False accordingly Note: This function must return True/False as a boolean, not as astringSample OutputWelcome! Lets play rock, paper, scissors.The rules of the game are:Rock smashes scissorsScissors cut paperPaper covers rockIf both the choices are the same, its a tiePlease choose (0) for rock, (1) for paper or (2) for scissorsYou chose Rock.The computer chose Paper.Paper covers rock. Computer wins!Do you want to continue playing? Enter (y) for yes or (n) for no.yWelcome! Lets play rock, paper, scissors.The rules of the game are:Rock smashes scissorsScissors cut paperPaper covers rockITP 115 Programming in Python p. 4 of 4If both the choices are the same, its a tiePlease choose (0) for rock, (1) for paper or (2) for scissors1You chose Paper.The computer chose Scissors.Scissors cut paper. Computer wins!Do you want to continue playing? Enter (y) for yes or (n) for no.nYou won 0 game(s).The computer won 2 game(s).You tied with the computer 0 time(s).Thanks for playing!Deliverables and Submission Instructions Create a folder on your computer calledITP115_a#_lastname_firstname(replace # with this lab number) Inside the folder, include your python source code Compress the folder (make a zip file) calledITP115_a#_lastname_firstname.zip(replace # with this assignment number) Upload zip file to Blackboard site for our course
Reviews
There are no reviews yet.