Question

Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember...

Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors.

Remember the rules:

1. Rock beats scissors

2. Scissors beats paper

3. Paper beats rock

The program should ask the users for their names, then ask them for their picks (rock, paper or scissors). After that, the program should print the winner's name. Note, the players may pick the same thing, in this case the program should say it's tie. when the user input an invalid choice, the program should inform the user.

Your program should contain two functions:

(1) compare_answers(u1, u1a, u2, u2a): This function takes four parameters (u1, u1a, u2, u2a), and returns a string. The parameters are all strings: u1(player 1 name), u1a (player 1 choice), u2 (player 2 name), and u2a(player 2 choice). The returned string should include the result of the game. (Submit for 6 points)

For example:

1. It's a tie!

2. Invalid input! You have not entered rock, paper or scissors, try again.

3. Rock wins! Good job 'u1'

4. Scissors win! Good job u2

(2) __main__: In the main, you do the following: (Submit for 4 points)

a. Prompt the user to input the name of player 1.

b. Prompt the user to input the name of player 2.

c. Prompt the user to input the choice of player 1.

d. Prompt the user to input the choice of player 2.

e. Print the result of the game.

Here are some example runs of the program:

Example 1: Player 1 inputs an invalid choice.

# FIXME 1: Complete the compare_answers function
def compare_answers(u1, u1a, u2, u2a):
    if u1a == u2a:
        pass
    elif u1a == 'rock':
        if u2a == 'scissors':
            return("Rock wins! Good job " + u1)
        elif u2a == 'Paper':
            pass
        else:
            pass
    
    # You need more elif in here
    
    else:
        pass


if __name__ == "__main__":
    # FIXME 2a: Prompt the user to input the name of player 1
    pass
    # FIXME 2b: Prompt the user to input the name of player 2

    # FIXME 2c: Prompt the user to input the choice of player 1

    # FIXME 2d: Prompt the user to input the choice of player 2

    # FIXME 2e: Call the function and print the result of the game
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of program code:-

Screenshot of output:-

Program code to copy:-

#Function takes four parameters and returns a string.
#The parameters are all strings: u1(player 1 name), u1a (player 1 choice),
#u2 (player 2 name), and u2a(player 2 choice).
#The returned string includes the result of the game.
def compare_answers(u1, u1a, u2, u2a):
if (u1a == u2a):
return "It's a tie!"
elif (u1a == "rock" and u2a == "paper"):
return "Paper wins!Good job "+u2
elif(u1a == "paper" and u2a == "rock"):
return "Paper wins!Good job "+u1
elif(u1a == "paper" and u2a == "scissors"):
return "Scissors wins!Good job "+u2
elif(u1a == "scissors" and u2a == "paper"):
return "Scissors wins!Good job "+u1
elif(u1a == "scissors" and u2a == "rock"):
return "Rock wins!Good job "+u2
elif(u1a == "rock" and u2a == "scissors"):
return "Rock wins!Good job "+u1
else:
return "Invalid input! You have not entered rock, paper or scissors, try again."

#main() function
def main():
#Prompt & read name of player1 from user
player1Name = input('Enter the name of player1: ')
#Prompt & read name of player2 from user
player2Name = input('Enter the name of player2: ')
#Prompt & read choice of player1 from user
#The choice entered by the user converted into lowercase using lower() function
player1Choice = input('Enter player1 choice(rock,paper,scissors):').lower()
#Prompt & read choice of player1 from user
player2Choice = input('Enter player2 choice(rock,paper,scissors):').lower()

#Calling function to get the result of game and print the result
print(compare_answers(player1Name,player1Choice,player2Name,player2Choice))

#Calling main() function
if __name__== "__main__":
main()

Add a comment
Know the answer?
Add Answer to:
Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....

  • (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...

  • C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this...

    C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...

  • Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that...

    Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that allows the user to play "Rock, Paper, Scissors". Write the RPS class. All code should be in one file. main() will be part of the RPS class, fairly small, and contain only a loop that asks the user if they want to play "Rock, Paper, Scissors". If they say yes, it calls the static method play() of the RPS class. If not, the program...

  • C++ You are asked to implement scissors-rock-paper game where the players are a computer and a...

    C++ You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user’s entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid...

  • Write a MARIE program to implement one round of rock paper scissors game. Your program should...

    Write a MARIE program to implement one round of rock paper scissors game. Your program should represent the three moves ‘rock’, ‘paper’ and ‘scissors’ with numbers 1, 2 and 3 respectively. When the program is run, there should be two input prompts, one after the other, to ask for player 1’s and player 2’s moves (a number 1, 2 or 3). Then the program would compare both numbers and apply the following rules to work out the winner. Paper beats...

  • You are asked to implement scissors-rock-paper game where the players are a computer and a user....

    You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user's entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid entry...

  • Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game...

    Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game in Python 3 that a user plays against the computer with the ability to save and load a game and its associated play statistics. Purpose: The purpose of this challenge is to assess the developer’s ability to create an interactive application with data persistence in Python 3. Requirements: Create a Rock, Paper, Scissors game in Python named rps.py according to the requirements specified in...

  • It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user...

    It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user selects 'p': 1. First the program should call a function named getComputerChoice to get the computer's choice in the game. The getComputerChoice function should generate a random number between 1 and 3. If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has...

  • Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock p...

    Help needed in Perl language program! Note : Perl Language Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock paper scissors) is an extremely popular hand game most often played by children. Often, it is used as a method of selection similar to flipping a coin or throwing dice to randomly select a person for some purpose. Of course, this game is not truly random since a skilled player can often recognize and exploit the non-random behavior of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT