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 python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

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