Use Python, please Part 3: Dice Wars In this part you are going to implement a simple
Question:
Use Python, please
Part 3: Dice Wars
In this part you are going to implement a simple children's dicegame called Dice Wars.
- Each player starts with 2 six-sided dice and 5 points.
- The objective of the game is to capture all of the otherplayer’s points.
- Players take turns throwing their dice simultaneously.
- The player whose sum is higher steals a point from the otherplayer.
- However, if that higher number is a double, the player gets tosteal two points instead of one!
- Play continues until one player has 10 points and the other has0.
Complete the function dice_wars, which takes two argumentsthat represent the rolls of the two players. Each character in eachstring is a digit character. These characters come in pairs becauseeach player is rolling a pair of dice.
For instance, dice_wars('524351', '652415') indicatesthat the players played three rounds:
- Player 1 rolled a 5 and a 2. Player 2 rolled a 6 and a 5.
- Player 1 rolled a 4 and a 3. Player 2 rolled a 2 and a 4.
- Player 1 rolled a 5 and a 1. Player 2 rolled a 1 and a 5.
We will assume that the input represents a partial game or afull game that ended with a win. You may assume that there are noextraneous rolls in the input. For instance, theinput dice_wars('52435162556624','65241524232322') contains an extra set of rolls at the endbecause player 1 actually wins at the end of the sixth round, yetthis input contains rolls for seven rounds of play. So these wouldnot be valid inputs, and your function doesn't have to check forbad inputs like these.
Process all of the given dice rolls, tracking the players'scores, and return both players scores in a single returnstatement. (Recall that a return statement can return two or morevalues.)
Take care that neither player has a negative score at theend!
Examples:
Function Call | Return Value |
---|---|
dice_wars('524351625566', '652415242323') | 10, 0 |
dice_wars('525551625566', '652415242323') | 10, 0 |
dice_wars('624253', '225533') | 5, 5 |
dice_wars('62142563', '24255133') | 7, 3 |
dice_wars('12142563', '24255136') | 4, 6 |
dice_wars('123412141244', '562355643455') | 0, 10 |