Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON PROGRAMMING DO NOT USE ANY KINDS OF LOOP (FOR AND WHILE) There are three possibilities when placing a new card: 1. The card can

PYTHON PROGRAMMING

DO NOT USE ANY KINDS OF LOOP (FOR AND WHILE)

image text in transcribed

There are three possibilities when placing a new card: 1. The card can be placed, using the described guidelines, in a row with fewer than 5 cards. It becomes 2. If the row already has 5 cards, the new card cannot be added. Instead, the new card must actually 4. Ploying (not scoring) a card gome called Toke5 for 6 Nimmt The" board" in the game Take5 consists of 4 rows of cards. Each row is in increasing arder and contains the new rightmost card in that row between 1 and 5 cards. An example is shown to the left. Players take turn placing new cards on the board, one at a time. New cards can only be placed at the rightmast end af a row. In the pracess of placing cards, a player may need to remove all the cards in a row, and will be assigned points based on the values in that row. The goal of the game is to have the lowest score after all rounds have been played. (Paints are actually based on the number of "bul horns" shown on the collected cords, but we will ignore that component of the game.) replace the entire row, and the player takes all the cards in that row. Consider, for example, placing 99. Based on the numbers, it must go in the fourth row. However, since that row already has 5 cards, the player will remove the cards there (13,30,50,88,93) and then 99 will become the only card in the fourth row If the new card is smallerthan all the rightmost cards, then the player must remove a row. For simplicity, we will assume that the player must choose the row which has the minimum value in its rightmost position, and then the new card will become the only card in that row. (In the real game, the player can choose any row, but usualy chooses the one with the fewest "buil horns", but we wil use a simpler rule.) For example, suppose we are trying to place 6. It is smaller than all the rightmost cards, so the player must take the third row (containing 8), since 8 is the smallest rightmost value, and then 6 becomes the only card in that row 3. To determine where a card is to be placed, you need to exanine the rightmost card in each row (70,19,8,93 in the board on the left). A card cannot be placed next to a bipger card, and must be placed next to the card its value is closest to. For example, 17 must be placed in the third row, next to 8; 22 must be placed in the second row, next to 19; .89 must be placed in the first row, next to 70. Consider the following new data definitions: A Card is a Nat between 1 and 104, inclusiv # A Row 13 a (113tof Card) containing between 1 and 5 Write a Python function tur tuke5, that consumes b, of type Board, and c, of type Card, where c is different from each of the cards already in b, and mutates b to reflect the playing of [as described previouslyl. In addition, the function returris the list of cards taken off the buard during the turri: alues, in strictly increasing order # A Board is a (listof Rox) of length 4 No Card appears more than once in a Board So, for example, the Take 5 board in our image is represented as in my_board: ity-board ifc is played on b without the player removing any cards las in possibility 11 then [ I is returned if should be plaved on a row which already contains five cards (as in possibility 2), then a row containing only c replaces that row, and the function returns the contents of the replaced row if zis smaller than the rightmost card in each row of as in possibility 3), then a row containing only c replaces the row with the smallest rightmost card, and the function returns the contents of the replaced row. [[6.1,10], 19, 18,19], [8], [13.30, 50, 88 , 93]] = . * For exarnple, consider the follawing sequerice of cals (in which the value af my board is updated by each successiwe call, as indicated. Restrictions: 1. Do not use LOOPS (for & while) tur: ake5 mboard, 17> and mutates y board to [(67, 7J], [9, 23, 23], [B, 17], [13, 30, 50, 36, 93] turntakas my hoard, 221 -> ,and mutates my board to [(67, 701, 19, -, 9, 22 ] , , 17], [13, 30, turntake5 (myboara, 99} -> [13, 30, so, 8, to 116% 70. 19, 18, 19, 221, 18, 19), 19911 52, DE, 3311 931.and mutates myDaard - - - * turn_cake5 my board. 5 B, 17], and mutates ny_ooard to t67, 7, , 18, 13. 221, 151, [591 There are three possibilities when placing a new card: 1. The card can be placed, using the described guidelines, in a row with fewer than 5 cards. It becomes 2. If the row already has 5 cards, the new card cannot be added. Instead, the new card must actually 4. Ploying (not scoring) a card gome called Toke5 for 6 Nimmt The" board" in the game Take5 consists of 4 rows of cards. Each row is in increasing arder and contains the new rightmost card in that row between 1 and 5 cards. An example is shown to the left. Players take turn placing new cards on the board, one at a time. New cards can only be placed at the rightmast end af a row. In the pracess of placing cards, a player may need to remove all the cards in a row, and will be assigned points based on the values in that row. The goal of the game is to have the lowest score after all rounds have been played. (Paints are actually based on the number of "bul horns" shown on the collected cords, but we will ignore that component of the game.) replace the entire row, and the player takes all the cards in that row. Consider, for example, placing 99. Based on the numbers, it must go in the fourth row. However, since that row already has 5 cards, the player will remove the cards there (13,30,50,88,93) and then 99 will become the only card in the fourth row If the new card is smallerthan all the rightmost cards, then the player must remove a row. For simplicity, we will assume that the player must choose the row which has the minimum value in its rightmost position, and then the new card will become the only card in that row. (In the real game, the player can choose any row, but usualy chooses the one with the fewest "buil horns", but we wil use a simpler rule.) For example, suppose we are trying to place 6. It is smaller than all the rightmost cards, so the player must take the third row (containing 8), since 8 is the smallest rightmost value, and then 6 becomes the only card in that row 3. To determine where a card is to be placed, you need to exanine the rightmost card in each row (70,19,8,93 in the board on the left). A card cannot be placed next to a bipger card, and must be placed next to the card its value is closest to. For example, 17 must be placed in the third row, next to 8; 22 must be placed in the second row, next to 19; .89 must be placed in the first row, next to 70. Consider the following new data definitions: A Card is a Nat between 1 and 104, inclusiv # A Row 13 a (113tof Card) containing between 1 and 5 Write a Python function tur tuke5, that consumes b, of type Board, and c, of type Card, where c is different from each of the cards already in b, and mutates b to reflect the playing of [as described previouslyl. In addition, the function returris the list of cards taken off the buard during the turri: alues, in strictly increasing order # A Board is a (listof Rox) of length 4 No Card appears more than once in a Board So, for example, the Take 5 board in our image is represented as in my_board: ity-board ifc is played on b without the player removing any cards las in possibility 11 then [ I is returned if should be plaved on a row which already contains five cards (as in possibility 2), then a row containing only c replaces that row, and the function returns the contents of the replaced row if zis smaller than the rightmost card in each row of as in possibility 3), then a row containing only c replaces the row with the smallest rightmost card, and the function returns the contents of the replaced row. [[6.1,10], 19, 18,19], [8], [13.30, 50, 88 , 93]] = . * For exarnple, consider the follawing sequerice of cals (in which the value af my board is updated by each successiwe call, as indicated. Restrictions: 1. Do not use LOOPS (for & while) tur: ake5 mboard, 17> and mutates y board to [(67, 7J], [9, 23, 23], [B, 17], [13, 30, 50, 36, 93] turntakas my hoard, 221 -> ,and mutates my board to [(67, 701, 19, -, 9, 22 ] , , 17], [13, 30, turntake5 (myboara, 99} -> [13, 30, so, 8, to 116% 70. 19, 18, 19, 221, 18, 19), 19911 52, DE, 3311 931.and mutates myDaard - - - * turn_cake5 my board. 5 B, 17], and mutates ny_ooard to t67, 7, , 18, 13. 221, 151, [591

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

What is job enlargement ?

Answered: 1 week ago

Question

what is the most common cause of preterm birth in twin pregnancies?

Answered: 1 week ago

Question

Which diagnostic test is most commonly used to confirm PROM?

Answered: 1 week ago

Question

What is the hallmark clinical feature of a molar pregnancy?

Answered: 1 week ago

Question

Choose an appropriate organizational pattern for your speech

Answered: 1 week ago

Question

Writing a Strong Conclusion

Answered: 1 week ago