Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import random # Step 0 : Define constants ROCK = 0 PAPER = 1 SCISSORS = 2 hand _ signal _ names = [

import random
# Step 0: Define constants
ROCK =0
PAPER =1
SCISSORS =2
hand_signal_names=["ROCK","PAPER","SCISSORS"] # define the names for each hand signal
# Read seed from input for random number generator
seed_value = int(input())
random.seed(seed_value)
# Step 1: Read player names and number of rounds
player1_name = input()
player2_name = input()
num_rounds = int(input())
# Make sure the number of rounds is valid
while num_rounds <1:
print("Rounds must be >0")
num_rounds = int(input())
# Output the player names and number of rounds
print(f"{player1_name} vs {player2_name} for {num_rounds} rounds")
# Step 4: Play the game for the specified number of rounds
player1_wins =0
player2_wins =0
# Loop through each round
for i in range(num_rounds):
# Generate a random hand signal for each player
player1_signal = random.randint(0,2)
player2_signal = random.randint(0,2)
# If both players make the same signal, it's a tie and we need to generate new signals
while player1_signal == player2_signal:
print("Tie")
player1_signal = random.randint(0,2)
player2_signal = random.randint(0,2)
# Determine the winner for this round and output a message
if player1_signal == ROCK and player2_signal == SCISSORS:
print(f"{player1_name} wins with rock")
player1_wins +=1
elif player1_signal == SCISSORS and player2_signal == PAPER:
print(f"{player1_name} wins with scissors")
player1_wins +=1
elif player1_signal == PAPER and player2_signal == ROCK:
print(f"{player1_name} wins with paper")
player1_wins +=1
else:
print(f"{player2_name} wins with {hand_signal_names[player2_signal]}")
player2_wins +=1
# Output the results
print(f"{player1_name} wins {player1_wins} and {player2_name} wins {player2_wins}")
IN PYTHON PLEASE

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

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

212. What is conservatism? What are its advantages?

Answered: 1 week ago

Question

6. Explain some strategies for dealing with conflict.

Answered: 1 week ago