Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a game of rock, paper, scissors I need to finish coding, Im having trouble using the proper variables and putting it into place.

This is a game of rock, paper, scissors I need to finish coding, Im having trouble using the proper variables and putting it into place.

The game will be played between a Human player and a Computer player.

The game needs to include 10 rounds

o The game will allow a user to determine how many rounds must be needed to win the match.

o A user will be allowed to enter their choice for rock, paper, or scissors.

o The computer will randomly choose rock, paper, or scissors.

o The game will display the winner of each round.

o When a player has reached the predetermined number of rounds to win the game, the winner will be displayed and the game will stop.

o Scores for each player will be displayed during each round and at the end of the match

Create a function called welcomeMessage. This function will display a welcome message to the user. The function does not require any arguments and does not return anything to the calling program. It is a void function.

o Create a function called numberOfRounds. This function will ask the user how many rounds are needed to win the game. This function does not require any arguments, but should return the number of rounds as an integer to the calling program.

o Create a function called userChoice. This function will ask the user if they want to select rock, paper, or scissors. This function does not require any arguments, but should return the choice of the user. I suggest returning an integer value to represent the choice.)

o Create a function called computerChoice. This function will mimic the computer player and will randomly choose rock, paper, or scissors. This function does not require any arguments, but should return the choice of the computer. I suggest returning an integer value to represent the choice.

o Create a function called determineWinner. This function will determine the winner of the round. The function requires 2 arguments; the choice of the human player and the choice of the computer. The function should return Human if the human player wins, Computer if the computer wins, and Tie if there is no winner.

o Create a function called main. This is the main function of your program. This function should do the following -

Declare the following variables and initialize all of them to 0.

1. totalRounds # total number of rounds needed to win the match

2. humanWins # number of wins by human player

3. humanLosses # number of losses by human player

4. humanTies # number of ties by human player

5. computerWins # number of wins by computer player

6. computerLosses # number of losses by computer player

7. computerTies # number of ties by computer player

8. userC # integer choice of human player

9. compC # integer choice of computer player

10. rndNbr # number of current round -

Declare a variable called winner and initialize to an empty string (). -

Call the welcomeMessage function to display the welcome message. -

Call the numberOfRounds function and assign the return value of this function to totalRounds.

Create a while loop that executes as long as neither the human player nor the computer player has won the prerequisite number of rounds (totalRounds).

Within the while loop

1. Increment the rndNbr by 1.

2. Call the userChoice function and assign the returned value to userC.

3. Call the compuerChoice function and assign the returned value to compC.

4. Call the determineWinner function and assign the returned value to winner.

5. Display the winner of the round.

6. Increment Wins-Losses-Ties for each player and display the current scores.

- Once a final winner has been determined, print the winner of the match and final scores for each player.

Im having trouble figuring this out past this point. I am aware that my returns in the else if statement dont work but I thought Id show my current work anyway. Thanks!

My code:

import random #random

totalRounds=0

humanWins=0

humanLosses=0

humanTies=0

computerWins=0

computerLosses=0

computerTies=0

userC=0

compC=0

rndNbr=0

winner=''

def welcomeMessage():

welcomeMessage=print("Welcome to the Rock, Paper, Scissors game")

welcomeMessage()

def numberOfRounds():

totalRounds = int(input("How many rounds would you like to play? :"))

return totalRounds

def userChoice():

print(input("Please enter 1 for rock, 2 for paper, and 3 scissors. :"))

def computerChoice():

compC = random.radint(1,3)

if compC == 1:

computer_rock()

elif compC == 2:

computer_paper()

else:

computer_scissors()

def computer_rock():

userC = input("Please enter 1 for rock, 2 for paper, and 3 scissors. :")

if userC == "1":

print ("You Tie, You chose Rock and the computer chose Rock.")

try_again()

if userC == "2":

print ("You Win, You chose Paper and the computer chose Rock.")

try_again()

if userC == "3":

print ("You Lose, You chose Scissors and the computer chose Rock.")

try_again()

else:

print("Try again?")

computer_rock()

def computer_paper():

userC = input("Please enter 1 for rock, 2 for paper, and 3 scissors. :")

if userC == "1":

print ("You Lose, You chose Rock and the computer chose Paper.")

try_again()

if userC == "2":

print ("You Tie, You chose Paper and the computer chose Paper.")

try_again()

if userC == "3":

print ("You Win, You chose Scissors and the computer chose Paper.")

try_again()

else:

print("Try again?")

computer_paper()

def computer_scissors():

userC = input("Please enter 1 for rock, 2 for paper, and 3 scissors. :")

if userC == "1":

print ("You Win, You chose Rock and the computer chose Scissors.")

try_again()

if userC == "2":

print ("You Lose, You chose Paper and the computer chose Scissors.")

try_again()

if userC == "3":

print ("You Tie, You chose Scissors and the computer chose Scissors.")

try_again()

else:

print("Try again?")

computer_scissors()

#try again function

def try_again():

choice = input("Would you like to play again? y/n")

if choice == "y"

def determineWinner():

if userChoice == computerChoice #this still needs work

return [humanWins, humanLosses, humanTies + 1]

return [computerWins, computerLosses, computerTies + 1]

elif userChoice == 1 and computerChoice == 3:

return [humanWins + 1, humanLosses, humanTies]

return [computerWins, computerLosses, computerTies]

elif userChoice == 2 and computerChoice == 1:

return [humanWins + 1, humanLosses, humanTies]

return [computerWins, computerLosses, computerTies]

elif user_choice == 3 and cpu_choice == 2:

return [humanWins + 1, humanLosses, humanTies]

return [computerWins, computerLosses, computerTies]

else:

return [humanWins + 1, humanLosses, humanTies]

return [computerWins, computerLosses, computerTies]

.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions