Question: Can you please change the code below in a different way but same inputs. import random def play _ game ( ) : player 1

Can you please change the code below in a different way but same inputs.
import random
def play_game():
player1_name = input("Enter player 1 name: ")
player2_name = input("Enter player 2 name: ")
rounds_to_play = int(input("No of rounds to play: "))
player1_score =0
player2_score =0
for round_num in range(1, rounds_to_play +1):
player1_round_score = random.randint(1,6)
player2_round_score = random.randint(1,6)
print(f"Round {round_num}-{player1_name}{player1_round_score} : {player2_name}{player2_round_score}")
player1_score += player1_round_score
player2_score += player2_round_score
print(f"Current Score {player1_name}{player1_score} : {player2_name}{player2_score}")
if player1_score > player2_score:
print(f"{player1_name} is the winner!!")
elif player1_score < player2_score:
print(f"{player2_name} is the winner!!")
else:
print("Its a draw!!")
# Run the game
play_game()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!