8.12. Mixed-up Code Questions

The following program should open a file, write a line, and close the file, but the code is mixed up. Drag the blocks of statements from the left column to the right column and put them in the right order. Watch out for extra pieces of code and indentation!

The following program counts the number of characters in the file “travel_plans.txt”, but the code is mixed up. Drag the blocks of statements from the left column to the right column and put them in the right order. First create a variable num and initialize it. Then open the file. Loop reading a line from the file and add the length of each line to num. Then print the result. Watch out for extra pieces of code and indentation!

The following program writes the squares of some numbers to the file “squared_numbers.txt”, but the code is mixed up. Drag the blocks of statements from the left column to the right column and put them in the right order. Watch out for extra pieces of code and indentation!

The following program should split the lines of “olympics.txt”, then print the name, team, and event of each athlete in a sentence. Unfortunately the code is mixed up. Drag the blocks of statements from the left column to the right column and put them in the right order. Watch out for extra pieces of code and indentation!

The next 5 questions refer to pollution data in the US from the following file. It contains a city, state :PM10 :PM2.5 where PM is the particulate matter and PM10 is particulate matter that is course and 2.5 to 10 micrometers in diameter such as dust from vehicles on the road. PM2.5 is particulate matter that is 2.5 micrometers in diameter or smaller which are produced by combustion from things like gas-powered vehicles or forest fires. If you want to see all of the data click on the Show button below. Once it appears, you can hide it again by clicking on the Hide button.

The following program prints the pollution information for all cities that start with a D, but the code is mixed up. Drag the blocks of statements from the left column to the right column and put them in the right order. Watch your indentation.

PM 2.5 is an air pollutant that is harmful at high levels. The following program prints the maximum PM 2.5 pollution found, but the code is mixed up. Drag the blocks of statements from the left column to the right column and put them in the right order. Watch your indentation.

The following program prints the minimum PM 2.5 pollution found, but the code is mixed up. Drag the blocks of statements from the left column to the right column and put them in the right order. Watch your indentation.

The following program prints the average PM 2.5 pollution found, but the code is mixed up. Drag the blocks of statements from the left column to the right column and put them in the right order. Watch your indentation.

The following program prints the average PM 2.5 pollution for a state, but the code is mixed up. Drag the blocks of statements from the left column to the right column and put them in the right order. Watch your indentation.

You have attempted of activities on this page