8.8. Mixed Up Code Practice¶
Try to solve each of the following. Click the Check Me button to check each solution. You will be told if your solution is too short, has a block in the wrong order, or you are using the wrong block. Some of the problems have an extra block that isn’t needed in the correct solution. Try to solve these on your phone or other mobile device!
The following program segment should print the value of n as long as n is less than 5. But the blocks have been mixed up and include an extra block that isn’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should print 0, 2, 4, 6 on separate lines by using a while loop. Arrange the code so that “accum” prints before increasing its value. The blocks have been mixed up and include an extra block that isn’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should print all even numbers from 0 to 8 (this includes 0 and 8). But the blocks have been mixed up and include an extra block that isn’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should result in an infinite loop. But the blocks have been mixed up and include an extra block that ins’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should calculate and print the average of a list of numbers using a for loop. Start by initializing the variable <i>sum</i> and then create the list of numbers. The blocks have been mixed up and include an extra block that ins’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should calculate and print the sum of all numbers between 0 and 30. Start by initializing the variable <i>sum</i>. The blocks have been mixed up and include an extra block that ins’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program segment should calculate the sum of all odd numbers between 0 and 30. Start by initializing the variable <i>sum</i> and loop through the odd numbers. The blocks have been mixed up and include an extra block that isn’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program should find the sum of every multiple of 3 between 3 and 36 and print the sum after each addition. But, the blocks have been mixed up and include an extra block that isn’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program should find the average pH of 6 water samples. But, the blocks have been mixed up and include an extra block that isn’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>
The following program should print the numbers 5 to 1 starting with 5. But, the blocks have been mixed up and include an extra block that isn’t needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the <i>Check Me</i> button to check your solution.</p>