solve problems and create computational representations of mathematical situations using coding concepts and skills
solve problems and create computational representations of mathematical situations by writing and executing efficient code, including code that involves conditional statements and other control structures
Conditional statements in code are used to compare items and can be used to sort data into categories for probability simulations. Have students first adapt the following flow chart for a simulation so that the coins are flipped multiple times. Next, have them write and execute the program. Afterwards, have them compare their flow chart with the program and make connections between the two.
Have students write code using conditional statements to convert between metric units:
read and alter existing code, including code that involves conditional statements and other control structures, and describe how changes to the code affect the outcomes and the efficiency of the code
Provide students with code that needs to be altered and/or expanded upon. For example, the following pseudocode can be used to simulate flipping a coin twice, storing the occurrences, and calculating the percentage for each result. Have students alter this code to simulate a greater number of flips while keeping the code efficient.
After the code for the probability simulation in Sample Task 1 has been altered to be more efficient, have students alter it again to compare the percentages of the coin flips for increased numbers of trials, such as 50 times or 3000 times.
Provide students with efficient code for a probability simulation for flipping a coin 10 times, and have them keep track of the theoretical and experimental probabilities. Ask them to alter the code so that the program flips the coin 100, 1000, and 10 000 times. Ask them to alter the code so that the program simulates the rolling of one die 10 times. Ask them to alter the code again to simulate the rolling of two dice.
Provide students with code to simulate rolling one die, 10 times. Ask them to alter the code to simulate rolling two dice: