← Back to Library
Lesson PlanFreeEN

CyberPi: Normal Distributions

In this lesson, students will explore the concept and features of normal distributions through Python. By taking the dice roll probabilities as an example, students will create data charts to represent all the possible outcomes and visualize the distribution of all the results of the sum of the two dice. Students will also measure and investigate the spread of the data to gain an understanding of the normal distribution concept.

Gr. 9–10
CyberPi: Normal Distributions

Lesson

Overview

Description

In this lesson, students will explore the concept and features of normal distributions through Python. By taking the dice roll probabilities as an example, students will create data charts to represent all the possible outcomes and visualize the distribution of all the results of the sum of the two dice. Students will also measure and investigate the spread of the data to gain an understanding of the normal distribution concept.

Objectives

  • Using lists in Python to store groups of values of the same data type

  • Modifying and extracting data from lists

  • Using the graphs (bar charts) capabilities of CyberPi to output data

Before the Lesson

Preparation

For the teacher:

  • Students should have a laptop or device with mBlock 5 installed from here: https://www.mblock.cc/en/download/ (desktop version or cloud-based version) and mBlock Python editor (mLink) installed. Click here to download the Python editor (mLink)

  • One CyberPi with USB-C cable 

  • Pocket shield (optional)

  • Worksheet: Lesson 11 Normal Distributions

  • Example Program: Lesson 11 Normal Distributions

  • Refer to the text-based beginner lessons in this bundle for more ways to teach text-based programming without the use of the CyberPi.

Introduction:

  • Data can be spread out in various ways due to the variation in the data.

  • The normal distribution is the most important data distribution, because it fits many natural phenomena.

  • In this lesson students will explore the concept and features of the normal distribution through Python.

  • Take the dice roll probabilities as an example, students will create data charts to represent all the possible outcomes and visualise the distribution of all the results of the sum of the two dice.

  • Students will measure and investigate the spread of the data to gain an understanding of the normal distribution.

Review

Warm Up

1. Let's begin by familiarizing ourselves with the key points of this lesson:

  • Identify the features of normal distribution model and explain why the kind of data distribution is a normal distribution

  • Write and execute repetitive algorithms to simulate probability experiments and create computational models that can demonstrate the normal distribution phenomena

2. Explain the concept of normal distribution.

  • Explain: The graph of a standard normal distribution has a symmetrical bell-shaped curve. The mean and median are equal in the normal distribution. Its standard deviation is 1.

  • Describe the graph of the normal distribution: In a normal distribution, most of the continuous data values tend to cluster around the mean, and the further a value is from the mean. Normal distributions are important in statistics because many continuous data in nature displays this bell-shaped curve when compiled and graphed.

3. Use the two dice rolling probability experiment to further explain the normal distribution and its application.

  • Ask: Suppose if you roll two dice and calculate the sum of the two dice, how many results do you get?

  • Ask students to write down and summarize all the possible results of the sum of two dice as well as the frequency of occurrence:

  • Say: It seems that this is not efficient enough to demonstrate the spread of the results of the sum. Let’s use Python to create a computational model for this probability experiment and graph a chart on CyberPi’s screen.

4. Have students fill out the ‘What I Know’ column of the K-W-L chart before the class.

Direct Instruction

Tour of mBlock 5

1. Open the mBlock software or mBlock 5 Web version.

2. Introduce students to the following key areas of the software interface:

Connect the CyberPi

3. Plug the CyberPi into the computer using the included cable. The CyberPi should boot up and the screen will display either the last program uploaded or the Home menu.

4. On the "Devices" tab in mBlock, click the "Add" button. Select CyberPi and click "Ok".

5. Click the "Connect" button. Then, select the USB port and click "Connect".

6. If connected successfully, the button will change to "Disconnect".

7. When you open the editor for the first time you will see these explanations mapping the interface. Encourage students to thoroughly read through it. Below are the screen captures if you ever need to reference them again.

Figure 1: To connect your CyperPi

Figure 2: Creating Projects and Project files (see How to Create, Open, Import, or Export Project Files)

Figure 3: Editing Area

Figure 4: Console Commands to run code and more

Figure 5: Terminal (Console) to display output from Editing Area

Figure 6: Libraries containing example program. Feel free to explore these at your leisure

Figure 7: Click "Tutorials" to view these helpful instructions anytime

Guided Practice

Hands On

Activity 1:

1. Have students read "Activity 1" in the example program

2. Ask students to think about the questions below:

  • The modules imported in this program

  • The variables displayed in the bar chart

  • Are ‘sum_list’ and ‘count_list’ variables? What are the values of them?

  • The function that sets the colour of the bar chart

  • The function that creates the bars

3. Explain the use of lists.

  • Say: ‘sum_list’ and ‘count_list’ are lists in Python. A list is an ordered collection of data. For example, the ‘sum_list’ contains all the possible results of the sum of the two dice, which you can see inside the square brackets.

  • Explain the list index: We use the ‘index()’ method to check the position of the sum of the two dice. The ‘index()’method returns the position of the given number in a list.

  • Remind students that the index of a list starts from ‘0’. For example, in the ‘sum_list’, the index of the item ‘2’ is ‘0’ and the index of the item ‘3’ is ‘1’.

4. Explain how to read and rewrite the value of an element on the list.

  • Explain: The ‘list.index[]’ expression can not only return the value of an item on the list according to the given index in the square brackets but also modify the value. In the example program, the ‘count_list[sum_index] += 1’ expression is to modify the value of the corresponding element by adding ‘1’.

  • Explain the relation between the ‘sum_list’ and ‘count_list’: The example program creates two lists: ‘sum_list’represents all the possible results of the sum of the two dice, and ‘count_list’ records the frequency of the corresponding sum. The ‘count_list[sum_index] += 1’ expression counts the frequency of the sum and modify the value in the corresponding position.

5. Explain how to graph a bar chart on the screen.

  • Ask students to identify the modules imported in Python which then allow them to program CyberPi’s screen and call the ‘random’ functions.

import cyberpi, random 

  • Point out the relevant functions for graphing the bar chart:

cyberpi.display.clear()

cyberpi.display.set_brush()

cyberpi.barchart.add()

  • Explain the syntax cyberpi.display.clear(): It is used to clear the content displayed on the screen. When we start a new program or project, we can use this syntax to clear the previous content shown on the screen and initialise the screen.

  • Explain the syntax cyberpi.display.set_brush(): To graph the bar chart, first, we can decide which colour the bars are. The parameter inside the round brackets can be made up of numbers or a string. If the parameters are integers – e.g. ‘(255, 255, 255)’, these digits or values represent a specified colour in the RGB colour model. The ‘RGB’ represents the three kinds of additive primary colours: red, green, and blue. The parameter in the round bracket is the RGB colour code – e.g. ‘(red, green, blue)’. However, the parameter of this syntax can be a string. Use these keywords to define the colour of the bar:

‘red’, ‘orange’, ‘yellow’, ‘green’, ‘cyan’, ‘blue’, ‘purple’, ‘white’, ‘black’

  • Remind students that the colour keywords must be all in lower case.

  • Explain the syntax cyberpi.barchart.add(): Use this syntax to import the data we have to the bar chart.

  • Explain the values represented by the bars. The values come from the ‘count_list’ that records the frequency of each sum.

6. Ask students to explain the program and draw a flowchart.

Independent Practice

Try It

Activity 2:

Task 1: Have students work individually to create another computational model for the coin toss probabilities.

  • Ask students to simulate the experiment of tossing two coins together. Calculate all the possible outcomes in this experiment and visualise the distribution with a bar chart.

  • Note: Create a list to store the ‘head’ and ‘’ and use the ‘random.choice’ function to randomly select one of the outcomes.

Task 2: Ask students to think about this question: Toss a coin three times and what is the probability of getting three heads, two heads, one head, and no head?

  • Have students plot a graph on CyberPi’s screen to demonstrate all the possible outcomes.

  • Have students list all the possible outcomes.

  • Have students calculate the probabilities of the events:

P(3 Heads) = P(HHH) = 1/8

P(2 Heads) = P(HHT) + P(HTH) + P(THH) = 3/8

P(1 Head) = P(HTT) + P(THT) + P(TTH) = 3/8

P(0 Head) = P(TTT) = 1/8

Task 3: Instruct students to plot the graph on the screen. Program CyberPi to set the bar colour and the numeric values represented by the bars.

Reflection

  • Have students fill out the K-W-L chart

  • Remind students to always comment their code, regardless of the simplicity

Extension

1. Have students calculate the normal distribution using a formula

Downloadable Material

Example Program

Worksheet

Educational Standards

Ontario - Grade 9-10 - Mathematics & Computer Science

Grade 9 Mathematics

  • Coming Soon!

Grade 10 Computer Science

B1: ICS20 Arithmetic Operations 

  • B1.1 use correct terminology to describe programming concepts; 

  • B1.2 describe the types of data that computers can process and store 

  • B1.4 determine the expressions and instructions to use in a programming statement, taking into account the order of operations

  • B1.5 identify situations in which decision and looping structures are required;

  • B1.6 describe the function of Boolean operators 

B2: Writing Programs

  • B2.1 use a visual problem-solving model to plan the content of a program;

  • B2.2 use variables, expressions, and assignment statements to store and manipulate numbers and text in a program 

  • B2.3 write keyboard input and screen output statements that conform to program specifications;

  • B2.4 write a program that includes a decision structure for two or more choices

  • B2.5 write programs that use looping structures effectively 

B3: Code Maintenance

  • B3.1 write clear and maintainable code using proper programming standards

  • B3.3 use a tracing technique to understand program flow and to identify and correct logic and run-time errors in a computer program;

  • B3.4 demonstrate the ability to validate a computer program using test cases.