197k views
5 votes
Write a function called play_dice that allows two players to roll dice and compare their scores. The player with the highest dice roll wins. If there's a tie, the function should re-roll dice for both players. It should keep rolling until there isn't a tie. The function will have 2 parameters, both strings representing the names of each player. It will return a string with this format: wins this round!! You need to use your roll_dice function from the previous question. You don't need to re-write that code here, just use ro11 dice function calls in this function definition. Also: Include a function call for your play dice function using the strings "Clarence" and "Leopold" as the arguments and rolling 3 dice for each player.

1 Answer

4 votes

Final answer:

The question is about developing a play_dice function in python that takes the names of two players as string parameters, rolls a dice for each player, compares the scores, and returns the name of the winner. In the event of a tie, the function should roll the dice again until a winner emerges.

Step-by-step explanation:

In order to play_dice function, we will be using the roll_dice function previously developed. This function will take two parameters, the names of the players as strings. In the function, both players will roll a dice and the function will compare the results. The player with the highest roll wins. If there is a tie, the function will roll the dice again and continue this process till there isn't a tie. The function will finally return a message indicating the winning player. For instance, if 'Clarence' and 'Leopold' are the players and assuming that 'Clarence' has won, the function will return "Clarence wins this round!!".

Learn more about play_dice function

User Jan Berndt
by
7.6k points