Reference no: EM133548888
Question: Describe the logic required in the algorithmic solution regarding the control structures used (sequence, selection and iteration). Provide detailed explanations.
The purpose is to convey that you have used the most efficient control structure(s) in the solution.
def correct_choice(player_name):
while True:
choice = input(f"{player_name}, please choose rock, paper, or scissors: ").lower()
if choice in choices:
return choice
else:
print(f"wrong choice. {player_name}, please choose rock, paper, or scissors.")
print("Welcome to Rock Paper Scissors!")
player1 = input("Enter Player 1's name: ").capitalize()
player2 = input("Enter Player 2's name: ").capitalize()
rounds = int(input("Enter how many rounds you want to play: "))
score1 = 0
score2 = 0
choices = ["rock", "paper", "scissors"]
print("\nLet's start!")
for round_num in range(1, rounds + 1):
print(f"\nRound {round_num}:")
choice1 = correct_choice(player1)
choice2 = correct_choice(player2)
print(f"{player1} chose {choice1}")
print(f"{player2} chose {choice2}")
if choice1 == choice2:
print("It's a tie!")
elif (choice1 == "rock" and choice2 == "scissors") or \
(choice1 == "paper" and choice2 == "rock") or \
(choice1 == "scissors" and choice2 == "paper"):
print(f"{player1} wins this round!")
score1 += 1
else:
print(f"{player2} wins this round!")
score2 += 1
print("\nGame Over!")
print(f"Final Score: {player1}: {score1} {player2}: {score2}")
if score1 > score2:
print(f"{player1} wins the game!")
elif score2 > score1:
print(f"{player2} wins the game!")
else:
print("The game is a tie!")
print(f"\nThank you, {player1} and {player2}, for playing!")