Loading…
Loading…
In this lesson, students will consolidate their previous knowledge and skills in coding and reflect upon the use of Python in a range of situations. This lesson will provide a set of Python programming tasks about Python data types, variables and lists, control structures, operations, expressions and functions. Classroom activities can take the form of individual or small group activities - depending on the classroom setup. This lesson also includes a capstone project for students to complete.
In this lesson, students will consolidate their previous knowledge and skills in coding and reflect upon the use of Python in a range of situations. This lesson will provide a set of Python programming tasks about Python data types, variables and lists, control structures, operations, expressions and functions. Classroom activities can take the form of individual or small group activities - depending on the classroom setup. This lesson also includes a capstone project for students to complete.
Students will review previous concepts taught throughout the Python Beginner and Advanced courses
Students will complete a capstone project
Welcome to this Python Coding lesson! Before you begin, take a few moments to let us know your thoughts or feedback on how we can improve this lesson in order to better enhance the learning experience that is delivered in your classroom!
Click here or follow the form below to complete the feedback survey once you've completed this lesson. Thank you!
This learning activity is the section of revision by the end of the course.
It aims to help students consolidate their previous knowledge and skills and reflect upon the use of Python in a range of situations.
The lesson plan provides a set of Python programming tasks about Python data types, variables and lists, control structures, operations, expressions, and functions.
Classroom activities can take the form of individual activities or small group activities–it depends on the class situation. This lesson plan also includes a capstone project.
Students should have a laptop or device with mBlock 5 installed (desktop version or cloud-based version) and mBlock Python editor (mLink) installed.
Worksheet: Mini Capstone & Review
Example Program: Mini Capstone & Review
1. 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

1. Summarise the rules of writing Python code, including keywords, case of letters, indentation, the name of a variable (or list), etc.
Say: Code is read much more often than it is written. We have read a lot of Python code during the learning activities, in particular, in the ‘Predict’ section. The readability and consistency of Python code matters.
Ask students to come up with some habits that should be taken when programming in Python. Have students work in pairs or groups to discuss with each other.
Invite volunteer students to share their opinions and then summarise those good habits for coding, for example:
Name variables, lists, or functions: Give a sensible name to the variable, list, or function you create so that anyone who see it could easily figure out what the variable, list or function refers to..
height = float(input(“Height:(metre) ”))
sum_list = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
def drawballs(n)
To avoid confusion, do not use the similar names (e.g., ‘a’ and ‘A’) to call variables, though the variable ‘a’ and the variables ‘A’, for example, can be differentiated by the mBlock Python editor. Nevertheless, avoid using numbers (e.g., ‘0’ and ‘1’) or roman numerals (e.g. ‘I’) to name variables.
Separate words with underscores: When naming a variable or list, it is a good habit to use an underscore like this:
principal_payment; interest_payment
Use abbreviations to name variables and lists: Use ‘var’ or ‘my_var’ to represent the name of a variable.
Use vertical whitespace or blank lines to separate code: The vertical whitespace or blank lines do not affect the execution of a program. Using blank lines appropriately can significantly improve the readability of code. Indicate clear steps inside code by using a blank line to separate two different groups of instructions. When creating a function, leave two blank lines before the function.


Use indentation: Indentation is important in Python. The indentation level of lines of code in Python determines how statements are grouped. To create a conditional algorithm or function, for instance, we put whitespace at the front to indicate which group of code belongs to a given control construct and function.
Use spaces instead of tabs to indent the code. Use four consecutive spaces to indent the code.
Use comments: Document code to briefly explain the code you write so that you or other people can figure out the instructions or purposes when using or reusing the code. Start the comment with a hashtag (‘#’). The editor will not run the comments as they are not part of the instructions.
The keywords: There are 33 keywords in Python. These words have specific meanings and functions. Therefore, these words cannot be used as the name of variables, lists, or functions.

The letter case: Python insists on a case-sensitive match, which means the ‘true’ and ‘True’ are different in Python.
2. Have students identify the keywords learnt in the previous lessons. Ask students to explain the functions of these keywords and under what situations they are applied.
The learnt keywords include: ‘and’, ‘break’, ‘def’, ‘elif’, ‘else’, ‘False’, ‘for’, ‘if’, ‘import’, ‘or’, ‘True’, and ‘while’.
3. Have students find the program below in Lesson 9 and ask them to modify the code by using the for loop.

4. Instruct students to add conditional constructs into the above program. Ask them to calculate the probabilities of:
(a) The sum is greater than 7 and is odd
(b) The sum is greater than 7 and is even
(c) The sum is either greater than 9 or is less than 4
(d) The sum is either 2 or 12
Review the logical operators before working on the exercise:

Review the comparison operators before working on the exercise:

5. Have students work in pairs or groups to discuss the use of the conditionals, the for loop and the while loop.
Ask them to think about under what situations and for what purposes they will use these conditionals, the for loop and while loop.
Ask them to explain the difference between using the for loop and using the while loop.
1. Have students work individually to plan on how to tackle the task as follows:
Task: Design a guessing game application using Python. Simulate the process of rolling two dice and guess which number is larger (or both are the same).
Requirements:
Define a function and call it to roll the virtual dice;
Use lists to store the outcomes of the rolling dice;
Create variables to count the number of correct and incorrect guesses;
Report one of the outcomes as a hint before guessing;
Report whether the guess is correct or not after guessing.
Ask students to think about and list the statements and expressions they may need to use to complete the task.
Tip:
def diceroll():
dice_list = []
dice_list.insert(index, item)
random.choice()
Differentiation: For advanced learners, ask them to calculate the probability of guessing the correct number. Have them draw a conclusion based on the experiment results.
Tip: Use a large size of the population.
2. Instruct students to design the guessing game application in Python and complete the task.

Another example solution:

Have students fill out the K-W-L chart using all the tools they used during their mini-capstone
Remind students to always comment their code, regardless of the simplicity
Similar to last lesson, breakdown your program so that it uses a few specific functions
A. Programming Concepts and Skills
A1. Data types and Expressions
A1.1 use constants and variables, including integers, floating points, strings, and Boolean values, correctly in computer programs;
A1.3 use assignment statements correctly with both arithmetic and string expressions in computer programs;
A1.4 demonstrate the ability to use Boolean operators (e.g., AND, OR, NOT), comparison operators (i.e., equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to), arithmetic operators (e.g., addition, subtraction, multiplication, division, exponentiation, parentheses), and order of operations correctly in computer programs;
A1.5 describe the structure of one-dimensional arrays and related concepts, including elements, indexes, and bounds;
A1.6 write programs that declare, initialize, modify, and access one-dimensional arrays.
A2. Control Structures and Simple Algorithms
A2.1 write programs that incorporate user input, processing, and screen output;
A2.2 use sequence, selection, and repetition control structures to create programming solutions;
A2.3 write algorithms with nested structures (e.g., to count elements in an array, calculate a total, find highest or lowest value, or perform a linear search).
A3. Subprograms
A3.1 demonstrate the ability to use existing sub- programs (e.g., random number generator, substring, absolute value) within computer programs;
A3.2 write subprograms (e.g., functions, procedures) that use parameter passing and appropriate variable scope (e.g., local, global), to perform tasks within programs.
A4. Code Maintenance
A4.1 demonstrate the ability to identify and correct syntax, logic, and run-time errors in computer programs;
A4.2 use workplace and professional conventions (e.g., naming, indenting, commenting) correctly to write programs and internal documentation;
A4.3 demonstrate the ability to interpret error messages displayed by programming tools (e.g., compiler, debugging tool), at different times during the software development process (e.g., writing, compilation, testing);
A4.4 use a tracing technique to understand pro- gram flow and to identify and correct logic and run-time errors in computer programs;
A4.5 demonstrates the ability to validate a program using a full range of test cases.
B. Software Development
B1. Problem-solving Strategies
B1.2 demonstrate the ability to solve problems independently and as part of a team;
B2. Designing Software Solutions
B2.1 design programs from a program template or skeleton (e.g., teacher-supplied skeleton, Help facility code snippet);
B2.2 use appropriate vocabulary and mode of expression (i.e., written, oral, diagrammatic) to describe alternative program designs, and to explain the structure of a program;
B2.4 represent the structure and components of a program using industry-standard program- ming tools (e.g., structure chart, flow chart, UML [Unified Modeling Language], data flow diagram, pseudocode);
B2.5 design user-friendly software interfaces (e.g., prompts, messages, screens, forms).
B3. Designing Algorithms
B3.1 design simple algorithms (e.g., add data to a sorted array, delete a datum from the middle of an array) according to specifications;
B3.2 solve common problems (e.g., calculation of hypotenuse, determination of primes, calculation of area and circumference) by applying math- ematical equations or formulas in an algorithm;
A. Programming Concepts and Skills
A1. Data Types and Expressions
A1.1 use constants and variables, including integers, floating points, strings, and Boolean values, correctly in computer programs;
A1.3 use assignment statements correctly with both arithmetic and string expressions in computer programs (e.g., numStudents = 4 + 2, name = “Devi”);
A1.4 use Boolean operators (e.g., AND, OR, NOT), comparison operators (i.e., equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to), arithmetic operators (e.g., addition, subtraction, multiplication, divi- sion, exponentiation, parentheses), and order of operations correctly.
A2. Control Structures and Simple Algorithms
A2.1 write programs that incorporate user input, processing, and screen output;
A2.2 use sequence, selection, and repetition control structures to create programming solutions;
A2.3 Demonstrate the ability to write algorithms with nested structures.
A3. Code Maintenance
A3.2 demonstrate the ability to correct syntax, logic, and run-time errors in computer programs;
A3.3 use workplace and professional conventions (e.g., naming, indenting, commenting) correctly to write programs and internal documentation;
A3.4 demonstrate the ability to interpret error messages displayed by programming tools (e.g., compiler, debugging tool), at different times during the software development process (e.g., writing, compilation, testing);
A3.5 demonstrate the ability to validate a program using test cases.
B. Software Development
B1. Problem-solving Strategies
B1.1 use various problem-solving strategies (e.g., divide and conquer, working backwards, process analysis, examples, extreme cases, tables and charts, trial and error) to solve program- ming problems;
B2. Designing Software Solutions
B2.1 design a simple program from a program template or skeleton (e.g., teacher-supplied skeleton, Help facility code snippet);
B2.2 use appropriate vocabulary and mode of expression (i.e., written, oral, diagrammatic) to describe alternative program designs and to explain the structure of a program;
B2.3 write subprograms (e.g., functions, procedures) that perform one well-defined task and use parameter passing and appropriate variable scope (e.g., local, global);
B2.4 use industry-standard programming tools (e.g., structure chart, flow chart, UML [Unified Modelling Language], data flow diagram, pseudo- code) to represent the structure and components of a computer program;
B2.5 design user-friendly software interfaces (e.g., prompts, messages, screens, forms).
B3. Designing Simple Algorithms
B3.1 use simple algorithms (e.g., validate entered data, count, accumulate, use random numbers) to design a program according to specifications;
B3.2 solve problems (e.g., calculation of gross pay; fuel consumption on a car trip; average of students’ marks; temperature at a given altitude, using the environmental lapse rate) by applying mathematical equations or formulas in an algorithm;