Simulate a game of rock-paper-scissors

Assignment Help Python Programming
Reference no: EM132356306

Rock,    Paper,    Scissors

Goals

Write a program that utilizes functions to simulate a game of rock-paper-scissors

Continue practicing with loops

Continue practicing with variable declaration and assignment

Setup

Create a new .py file in your desired directory, and rename the file

When you name the code, use the following naming convention

ITP115_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 email

Description/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 computer’s 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:

Rock smashes scissors (If one player chooses rock and the other chooses scissors, then the player who chooses rock wins).

Scissors cut paper (If one player chooses scissors and the other chooses paper, then the player who chooses scissors wins).

Paper covers rock (If one player chooses paper and the other chooses rock, then the player who chooses paper wins).

If both players make the same choice, then it is a tie.

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 computer’s choice, get the player’s choice, and play a round (see who won)

Since playRound will return the result of who won the game, you will also need 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 of player 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)

Input: two integers—one representing the computer’s choice (0, 1, or

2) and the other representing the player’s 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 a string

Sample    Output

Welcome! Let's play rock, paper, scissors.

The rules of the game are:

Rock smashes scissors

Scissors cut paper

Paper covers rock

If both the choices are the same, it's a tie

Please choose (0) for rock, (1) for paper or (2) for scissors

0

You 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.

y

Welcome! Let's play rock, paper, scissors.

The rules of the game are:

Rock smashes scissors

Scissors cut paper

Paper covers rock

If both the choices are the same, it's a tie

Please choose (0) for rock, (1) for paper or (2) for scissors 1

You 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.

n

You 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 called

ITP115_a#_lastname_firstname
(replace # with this lab number)

Inside the folder, include your python source code

Compress the folder (make a zip file) called

ITP115_a#_lastname_firstname.zip

(replace # with this assignment number)

Upload zip file to Blackboard site for our course

Reference no: EM132356306

Questions Cloud

Term project : The project paper report must be written in your own words and must be a minimum of 5 double-spaced typed pages with at least three references or bibliography
Application of research is essential to achieving successful : In nursing practice, accurate identification and application of research is essential to achieving successful outcomes.
Uses epidemiological measures : find an article or news story that uses epidemiological measures. Provide a hyperlink to the article/news story, an overview of the story
Execute a simple program to compute tax on an order amount : Execute a simple program to compute the tax on an order amount. The program should prompt for the order amount and the state.
Simulate a game of rock-paper-scissors : Write a program that utilizes functions to simulate a game of rock-paper-scissors. Write a program that allows the user to play Rock, Paper, Scissors.
Schizophrenia are two relatively common behavioral disorders : Bipolar disorder and schizophrenia are two relatively common behavioral disorders. Compare and contrast these disorders.
What are some known causes of cancers in humans : What are some known causes of cancers in humans? Describe an experiment to test your hypothesis.
Apply the skills and tools necessary to deal with behavior : HA510- Apply the skills and tools necessary to deal with behavior and change in healthcare organization. How difficult will it be for someone to analyze answers
Define these concepts from food and beverage perspective : Define these concepts from a food and beverage perspective. Examine the competitive nature of the Sydney food and beverage industry.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a client pingprogram in python

Write a client pingprogram in Python. Your client will send a simple ping message to a server, receive a correspondingpong message back.

  Display the count of the groups and final balance

Using the For.. loop, Write a program to ask the user for 7 deposits. As the user enters a deposit amount, update the balance using accumulation concept.

  Submit your code and any additional images or other things

These are the basic features that your game should have. You should submit your code and any additional images or other things that you need to run the program.

  Write a program in python to draw a simplified face

Write a program in Python to draw a blue triangle in a drawing window. Write a program in Python that moves the triangle in an animated movement. Write a program in Python to draw a simplified face.

  Create list of valid entries and the correct results

Create list of valid entries and the correct results for each set of entries. Then, make sure that the results are correct when you test with these entries.

  How to create an output label and associate

How to create an output label and associate it with a StringVar object. Name your Python program name_address_GUI.py

  Make a gui program that calculates the hypotenuse

Make a GUI program that calculates the hypotenuse of a right triangle after the user enters the lengths of the two short sides and clicks the Calculate button.

  Make automobile class that will be used by a dealership

Make automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class.

  Write a fuunction that computes future investment value

Write a fuunction that computes future investment value at a given interest rate for a specified number of years.

  Write a regular expression that will replace all occurrences

Using the sub() method from the re package substitute all occurrences of the 'pattern' with 'substitution'.Output to the console replace_results.

  Allow the user to specify the file name on the command-line

Allow the user to specify the file name on the command-line. If the user doesn't specify any file name, then prompt the user for the name.

  Add a new function called print box to your program

Add a new function called print_box to your program. print_box will manage the other three functions by calling et_size to get a number from the user.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd