88 minute read

Software and hardware

Next Article
About the series

About the series

Peer feedback Giving and receiving peer feedback ensures that students gain confidence and develop their own learning techniques. It also provides teachers with more time to facilitate formative feedback with individual students. The first time you ask students to give peer feedback, go through some examples of what good peer feedback looks like and ensure that students understand that they are giving supportive suggestions to each other. Students can give peer feedback by: l giving comments about a specific design, solution or idea l offering a solution or strategy to improve work, including possible revisions or suggested examples l leaving their peers with something to think about or take action on l ensuring that their feedback directly references the task, requirements or skill l being kind and supportive in the way they word their comments and suggestions. Final projects and knowledge tests While the course is not formally assessed, the ‘Final project’ at the end of each unit provides an opportunity to assess the skills that students have gained through the unit. Here, students work independently on a series of tasks to demonstrate their knowledge, skills and understanding of some of the learning outcomes linked to the ‘Scenario’ at the start of the unit. Note that not all the learning objectives are covered in the final project. Do check carefully through the list of learning objectives. The Boost online resources also provide a quiz for every unit of the Student’s Book. Recording the results from these quizzes will enable teachers to see where a student’s strengths and weaknesses lie. Teachers can then use this information to provide extra support and practice for students where needed. For a visual representation, teachers could use the results to perform a RAG (red–amber–green) analysis. Highlight scores from 1 to 19 as red, meaning further support is needed; scores from 20 to 31 as amber, meaning that learners have mostly understood but need support in some areas; and scores from 32 to 40 as green, meaning that learners have a good understanding and few weaknesses. The quiz questions each have a clear focus, such as understanding keywords, understanding program code, and key concepts from the module. Recording the results of each individual question would enable teachers to see which specific aspects students as a class are stronger in and in which they are less confident. Analysis of this nature can help teachers to reflect on their own practice and consider whether classroom techniques could be changed or adapted in the future. The ‘Review’ sections of the Teacher’s Guide give an opportunity to revisit learning from the lesson and can be used to assess whether students have understood concepts and how well they are able to apply them to a scenario. Software and hardware A summary of the software and hardware needed is given at the start of each unit in the Student’s Book and each Teacher’s Guide lesson. Students will need access to the following on their personal devices to complete the activities in the Student’s Book: l a web browser and an active internet connection l word-processing software, e.g. Microsoft WordSample ©Hodder Education 8

l presentation software, e.g. Microsoft PowerPoint l spreadsheet software, e.g. Microsoft Excel l database software, e.g. Microsoft Access l Python l MicroPython – https://python.microbit.org/ l a micro:bit and USB connection cable l a flowchart-drawing application, e.g. https://app.diagrams.net (optional). Note: Students are not being assessed on their skills in the use of word-processing or presentation applications, as these do not form part of the curriculum framework. However, these applications are sometimes suggested as a tool for students to use when completing the activities. It is presumed that students have a basic understanding of such applications before starting the course. Worksheets, for example, could be completed digitally or by hand on a printed copy. Sample ©Hodder Education 9

Advertisement

Learning objectives overview

These learning objectives and associated codes are reproduced from the Cambridge Lower Secondary Computing curriculum framework (0860) from 2021. This Cambridge International copyright material is reproduced under licence and remains the intellectual property of Cambridge Assessment International Education.

Learning objective Curriculum framework code Student’s Book pages Teacher’s Guide pages Online resources Computational thinking

Follow, understand, edit and correct algorithms that are presented as pseudocode. 9CT.01 49–50 53–54

Follow flowchart or pseudocode algorithms that use loops. 9CT.02 34–35, 37–38 36–37, 40–41 9.1 Knowledge Test 9.1.5 Worksheet 8 9.1.6 Worksheet 10

Know how to create algorithms using flowcharts and pseudocode. 9CT.03 9, 44–45, 52 15, 43–46, 58–59

Understand and use iteration statements, limited to count-controlled loops, presented as either flowcharts or pseudocode. 9CT.06 34–35, 52 36–37, 60

Predict the outcome of algorithms that use iteration. 9CT.07 37–38 40–41 9.1.5 Worksheet 9

Compare and contrast algorithms designed for the same tasks to determine which is best suited to the purpose. 9CT.08 34–35 36–37

Combine multiple constructs (sequence, selection, count-controlled iteration) to write algorithms as flowcharts or pseudocode.

9CT.09 44–45, 52 43–46, 58–59 Presenting choices: Combining constructs9.1 Sample ©Hodder Education

10

9.1 Presenting choices: Combining constructs

Learning objective Curriculum framework code Student’s Book pages Teacher’s Guide pages Online resources

Programming

Explain the purpose of a one-dimensional array.

9P.01 37–38, 44–45, 52 40–41, 43–46, 60 9.1.6 Worksheet 11 9.1 Knowledge Test Identify and describe data types in text-based programs, including integer, real, character, string and Boolean.

9P.02 15, 52 17–18, 58 9.1.1 Worksheet 1 9.1.1 Worksheet 2 9.1.5 Worksheet 9 9.1 Knowledge Test Know how to develop text-based programs with count-controlled loops.

9P.03 30, 34–35, 37–38 35, 36–37, 40–41 FoodSelection ChatbotV3.py 9.1.6 Worksheet 10 9.1.5 Worksheet 8 Know how to access data from an array using a textbased language.

9P.04 30, 34–35, 37–38 40–41, 63 9.1.6 Worksheet 10 9.1.7 Worksheet 12 Know how to develop text-based programs using string manipulation, including length, uppercase and lowercase.

9P.05 49–50, 53 53–54, 63 stringManipulation.py 9.1 Knowledge Test Use iterative development on software prototypes to produce solutions to problems.

9P.06 18, 28, 44–45, 53 21–22, 30–33, 43–46, 63 pizzaChatbotV3.py ActivitiesChatbotV3.py Evaluate the processes that are followed to develop programs.

9P.07 53 63 Know how to develop and apply test plans that include normal, extreme and invalid data.

9P.08 48, 53 49–50, 63 TestProgram.py 9.1.8 Worksheet 13 Identify test data that covers normal, extreme and invalid data.

9P.09 48, 53 49–50, 63 TestProgram.py 9.1.8 Worksheet 13 9.1.8 Worksheet 14 9.1 Knowledge Test Identify a range of errors, including syntax, logic and runtime errors.

9P.10 28, 48, 53 30–33, 49–50, 63

9.1.4 Worksheet 7 TestProgram.py 9.1.8 Worksheet 13 9.1.8 Worksheet 14 travelChatbotV1.py 9.1 Presentation 9.1.4 Visual 2Sample ©Hodder Education 11

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Learning objective Curriculum framework code Student’s Book pages Teacher’s Guide pages Online resources

Programming

Use trace tables to systematically debug textbased programs.

9P.11 23, 28, 53 25–28, 30–33, 63

9.1.3 Worksheet 4 9.1.3 Worksheet 5 9.1.4 Worksheet 6 Background information This unit develops students’ knowledge, skills and understanding of programming in Python. Students learn how to write programs to include sequence, selection and count-controlled iteration. They learn how to store more than one item in an array and how to access this information within a program. They learn how to structure count-controlled iteration and arrays in pseudocode. They learn how to create and use a trace table to track a variable effectively through a program as a form of test to find and fix errors. They learn about the different types of errors that can occur in a program and how to find and fix them using trace tables, error messages and test plans. In preparation for this unit, students should have access to a text-based programming application; the content of this unit has been developed using Python. Prior knowledge Students should already be familiar with basic programming in Python from Stages 7 and 8; in particular, how programs can be developed using sequence and selection with the use of input, output, variables and if… elif… else. Where this is not the case, students may require additional guidance when developing programs in Python. Prior to starting this unit, students should already be able to: l develop a Python program using an iterative process l follow and understand an algorithm presented as pseudocode l explain and use the rules AND, OR and NOT to create logic within an algorithm l follow flowcharts and pseudocode algorithms that use conditional statements l predict the outcome of algorithms that use pseudocode l create a Python program that uses conditional statements l create a program in Python that uses a range of different data types l develop a Python program that uses rules involving AND, OR and NOT l decompose a problem into smaller sub-problems to make it easier to solve l identify and describe the data types in a Python program l develop and apply a test plan to ensure that a Python program or algorithm works correctly. Cambridge learner attributes Cambridge students are encouraged to display these attributes in every lesson. The tasks in the Student’s Book are designed to support these attributes, e.g. through partner and group work; through peer evaluation; and through independently thinking through a problem even if the outcome is not as expected. Sample ©Hodder Education 12

9.1 Presenting choices: Combining constructs

Some specific examples for this unit are given below.

Responsible through discussion; when students explore how to develop an algorithm as pseudocode and develop a program to act as a chatbot, they show that they can work collaboratively with others in a respectful and responsible manner. They give other students the opportunity to express their opinions during discussion.

Innovative in the ‘Final project’; students apply the skills they have developed using Python, including the use of arrays, count-controlled iteration and string manipulation, to produce innovative solutions to the problems in the ‘Scenario’. Students are encouraged to develop their chatbot program in

Python and test it iteratively by developing and applying a test plan with a range of test data.

Confident in the ‘Practise’ tasks and ‘Final project’; students follow and edit pseudocode and Python, and become more confident in writing program code in Python, including using arrays and countcontrolled iteration. They explore how different

Python syntax can be applied in a confident and

expressive way to solve problems presented to them in the ‘Scenario’. Engaged in tasks across the unit; students develop new skills related to the development of textbased programming in Python and pseudocode. The use of a range of program code will ensure engagement and enquiry in the practical elements of this unit of work. Reflective through regular discussions with a partner, a small group or as a class about what they have learned; students predict what the pseudocode or programs will do or share thoughts on how to develop a program further. In the ‘Evaluation’, students review each other’s final solution to the ‘Scenario’. Across the unit, students reflect on their work, e.g. they have the opportunity to evaluate the impact of using an iterative process for program development and they develop and apply test plans. Students are encouraged to use the feedback from their tests to make improvements to their work. Sample ©Hodder Education 13

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

UNIT 9.1 LESSON 1

Student’s Book pages 8–15

l Get started! l Warm up l Scenario l Chatbots l Data types and collecting variable data

Boost online resources

l 9.1.1 Worksheet 1 l 9.1.1 Worksheet 1 Answers* l 9.1.1 Worksheet 2 l 9.1.1 Worksheet 2 Answers*

l activityChatbotV1(Teacher).py* l activityChatbotStretch(Teacher).py* l 9.1 Keywords flashcards * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks. Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the worksheets digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objective Success criteria for students

9P.02 Identify and describe data types in text-based programs, including integer, real, character, string and Boolean. I can identify and describe data types in Python programs, including integer, real, character, string and Boolean. 9CT.03 Know how to create algorithms using flowcharts and pseudocode. I can create algorithms using flowcharts and pseudocode.

Keywords

Flashcards for the following keywords are available in the Boost online resources: l chatbot l machine learning l character l cast l test plan l flowchart l data type l integer l pseudocode l rule-based chatbot l program l real l naming convention l evolving l algorithm l float l camelCase l artificial intelligence (AI) l string l concatenation l snake_caseSample ©Hodder Education

14

9.1 Presenting choices: Combining constructs

Starter

Get started! (Student’s Book page 8) l Read the ‘Get started!’ box with the class. Students, in pairs, should take turns to think of an object and the other student should ask 20 questions that can be answered 'yes' or 'no' to guess the object. It is important for the questions to be ‘yes’/‘no’ style to narrow down the object being guessed and link to how selection works. l Discuss the use of questions to help to solve a problem: – When might the answers to a series of questions be used to find a solution? Examples may include a series of medical questions to find the correct diagnosis; an interview with a job applicant to find out whether they are suitable for a role; an interview with a suspected to find out whether they are guilty or innocent. – Why is more than one question important? A question can lead into another based on the answer; more than one question may be required to ensure that the correct solution is reached – for example in the medical scenario where a series of questions around symptoms is important to help with the diagnosis and to choose the correct next steps. l Read the ‘Did you know?’ box with the class to introduce what a chatbot is and where students may have met one before. Warm up (Student’s Book page 9) l Read the ‘Warm up’ box with the class. l Discuss with students how the answers to questions help them to make decisions in different scenarios. Refer to the flowchart in the box to illustrate a series of questions that lead from one to another to help to make a decision. l Ask students to use paper or flowchart software such as https://app.diagrams.net to draw a flowchart for choosing a topping for a pizza. Encourage students to consider the questions that need to be asked and how they should be asked clearly, e.g. Would you like pepperoni, ham and pineapple, or vegetarian? IF selection == 1 No IF selection == 2 No OUTPUT Vegetarian pizza OUTPUT Pepperoni pizza

OUTPUT Ham and pineapple pizza YesYes Start OUTPUT "Add 1 for pepperoni, 2 for ham and pineapple or 3 for vegetarian" selection = INPUT Sample ©Hodder Education 15

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Scenario (Student’s Book page 10) l Read the ‘Scenario’ with the class. Remind students that they explored selection in Stage 7 in flowcharts and in Stage 8 in Python. l Discuss how this unit will allow students to develop their Python skills further, to create a program that acts as a chatbot to help them when selecting options or areas of study to continue. Do you remember? (Student’s Book page 11) As a class, review the concepts outlined in this box. Revisit any concepts with students where necessary. Activity notes and answers Chatbots Learn (Student’s Book page 11) l Read the ‘Learn’ box as a class to highlight the difference between the two types of chatbots. l Focus on rule-based chatbots and how they link with the type of chatbot program students will create. l Encourage discussion around students’ experiences with chatbots, e.g. using a chatbot to guide them when deciding on a new clothes item or song to listen to. l Check that students understand the difference between a rule-based chatbot and a chatbot with artificial intelligence. Practise (Student’s Book page 12) 1 Encourage students to discuss the difference between rule-based and artificial intelligencebased chatbots and which is more suited to development in Python. 2–3 Students should work in pairs find out about retail companies that have chatbot-style support; they should look at the questions in the ‘Practise’ box to support their reviews. Two examples of retail companies are: – H&M: www2.hm.com/en_gb/customer-service/contact.html – Nivea: www.nivea.com.au/highlights/sun-chat Encourage students to discuss the chatbots they found and the similarities and differences between them. Ask questions to guide the discussion, e.g.: – How do the chatbots start? – Are there any questions that more than one chatbot uses? – How do the questions flow into one another? Answers 1 Rule-based chatbot: A chatbot that asks a set of questions that the user answers. Artificial-intelligence chatbot: A chatbot that has the ability to learn and develop its own programming from the experiences it encounters. 2–3 The answers below are based on chatbots for the two retail companies H&M and Nivea. H&M a To support customers. b Customers over 18. c An introduction that states that there is no one available to chat but that the chatbot can help with frequently asked questions, and if it can’t answer the question it can provide contact details of a person who can. d Simple layout and very clear about its capabilities to allow the user to know what to expect.Sample ©Hodder Education 16

9.1 Presenting choices: Combining constructs

Nivea a To offer customers product recommendations and insightful tips and tricks. b Customers who use skin products. c It uses images to start the customer’s selection process. d The images are clear and easier to understand than reading questions; very visual compared with the H&M textual chatbot. Data types and collecting variable data Learn (Student’s Book page 12) l Start by recapping the learning from previous stages where students have used data types. Ask students to share their knowledge and use of data types, e.g. using a string with quotation marks around it or an integer (a whole number). l Read the ‘Learn’ box as a class. Highlight the different data types available in Python, and that the ‘character’ data type is not used in Python, as a string can hold a single character. l Focus on the impact on the program when the data type is not set as an integer, and that adding two strings together means just placing them side by side instead of using addition. l Demonstrate using Python the effect of using input() with and without int() using the examples in the ‘Learn’ box. l Check that students understand that a ‘real’ data type is the same as a ‘float’, and when programming in Python they need to use ‘float’ to define the data type: float(). Practise (Student’s Book page 15) 1–2 Students should work in pairs to discuss what the flowchart algorithm is going to do and where the variables are. They should write all the variables in a table to plan the variables and the data types to use when writing the program. 3 Students should use their plans and the flowchart to create the pseudocode for the algorithm, remembering the key characteristics: uppercase for START, STOP, INPUT, OUTPUT; selection key areas, e.g. IF, THEN, ELSE; and the use of indentation. Encourage students to compare the pseudocode and flowchart to check they have covered all areas. 4 Once the students have planned the algorithm in pseudocode, they need to use a Python editor to create the program to match. When combining text with variable content in outputs, remind students about using quotation marks around the text output and a comma in between the text and the variable name. Remind students to save their program as activityChatbotV1.py. 5 Remind students that they should structure a test plan using a table like the ones they used in previous stages, e.g.: Test Test data Expected outcome Pass/fail 6–7 Ensure that students discuss the different data types and how the variable name is just as important as the data type. Answers 1 The program starts by defining two variables: adults as False and cost as 7.95. The user is asked to enter an activity and the answer stored in the variable activity. The user is asked their age and the answer stored in the variable age. If the age is greater than or equal to 18, then the variable adult is changed to True. If the variable adult is True, then the variable cost is changed to 9.50. The program will then output As you are ‘age’ it will cost you ‘cost’ to go ‘activity’.Sample ©Hodder Education 17

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

2 Variable name Data type

adult Boolean cost Float or Real activity String age Integer 3 For example: 4 For the completed program, refer to activityChatbotV1(Teacher).py. 5 Each student’s test data will be different depending on the day and activities they add when prompted. Here is an example test plan.

Test Test data Expected outcome Pass/fail

1 activity = swimming age = 19 As you are 19 it will cost you 9.50 to go swimming

Pass 6–7 Variables and data types can help when creating the program code. Planning the variables and data types can help the programmer when writing the program code. If it is created correctly with the correct data types defined, then the program will run as expected. Examples of data types and which data type is not used in Python are: – string example: "string" – integer example: 1 – float/real example: 0.5 – character is not used in Python – Boolean example: Yes/No Review l Provide students with 9.1.1 Worksheet 1. Ask them to read the descriptions and write the Python code to match the variable and data type required. l For answers, refer to 9.1.1 Worksheet 1 Answers. START adult = False cost – 7.95 activity = INPUT “Enter the activity” age = INPUT “Enter your age” IF age >= 18 THEN adult = True ENDIF IF adult == True THEN cost = 9.50 ENDIF OUTPUT “As you are”, age, “it will cost you”, cost, “to go”, activity STOP Sample ©Hodder Education 18

9.1 Presenting choices: Combining constructs

Homework l Provide students with 9.1.1 Worksheet 2 and ask them to highlight where the data type needs to be defined, identify the data type required and write out the correct Python program code. l For answers, refer to 9.1.1 Worksheet 2 Answers. Chatbots Stretch: There is an opportunity for students to present their findings to tasks 2–3 to the rest of the class. This allows them to showcase their understanding and support others with their findings. Support: It may benefit some students to identify similarities and differences. Ask students to think about how the chatbot communicates with the customer, and to decide which chatbot they feel is better and why, e.g. The use of images on the Nivea chatbot means that the customer is able to make a selection based on the visual options. The H&M chatbot is text-based and relies on the user adding a question that the chatbot understands and is be able to answer. Data types and collecting variable data Stretch: There is an opportunity for students to add to the pseudocode and chatbot program by considering how to make this program feel more like a chatbot. A chatbot would have more of a userfriendly start to the program. Ask students to consider how the program is presented to the user. For an example solution, refer to activityChatbotStretch(Teacher).py. Support: It may benefit some students to have additional support when considering how to combine the output with the contents stored in the variables. Remind students to add commas between the text output for the variables in the print statement. It can be helpful to write the text output sections and the variable names on individual sticky notes and place them together to plan the program code. Differentiation START OUTPUT “Let me help you find out the cost of your chosen activity” OUTPUT “I will need to know your chosen activity and age to help you further” adult = False cost – 7.95 activity = INPUT “Enter the activity” age = INPUT “Enter your age” IF age >= 18 THEN adult = True ENDIF IF adult == True THEN cost = 9.50 ENDIF OUTPUT “As you are”, age, “it will cost you”, cost, “to go”, activity STOP Sample ©Hodder Education 19

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

UNIT 9.1 LESSON 2

Student’s Book pages 16–18

l Developing in iterations

Boost online resources

l 9.1 Presentation l 9.1.2 Visual 1 l 9.1.2 Worksheet 3 l 9.1.2 Worksheet 3 Answers* l pizzaChatbotV1(Teacher).py*

Starter

l Display 9.1 Presentation slide 1. Ask students to look at the two examples of program code.

Explain that the second example is a development of the original program code (the first example). l Ask students to spot the differences between the two examples. What is the benefit of the change that has been made and why has it been done? The data type is not set in example 1, which means that the program would not run correctly. The other difference is that, in the second example, the three lines of code with the options to choose between have all been included in the input statement. This improves the efficiency of the code as it reduces the amount of code required. l Explain that developing in iterations means testing a prototype, reviewing it and developing it to ensure that the final version is as good as possible.

l pizzaChatbotV2(Teacher).py* l pizzaChatbotV3(Teacher).py* l pizzaChatbotV2Stretch(Teacher).py* l 9.1 Keywords flashcards * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks. Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the worksheets digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objective Success criteria for students

9P.06 Use iterative development on Python prototypes to create solutions to problems. I can use iterative development on Python prototypes to create solutions to problems.

Keywords

Flashcards for the following keywords are available in the Boost online resources: l evolving l user requirements l prototype l iterate/iterative/iteration l trace table

AQ: <this file is not in the folder with the Boost resources> Sample ©Hodder Education 20

9.1 Presenting choices: Combining constructs

l Provide students with 9.1.2 Visual 1 and ask them to write the pseudocode for the selection section of the program. This is the solution. Activity notes and answers Developing in iterations Learn (Student’s Book page 16) l Read the ‘Learn’ box as a class and recap the iterative process introduced in Stage 8 and the importance of a prototype. l Focus on the development of a chatbot program from pseudocode through to program code. l Highlight the link to software development and the importance of testing and reviewing in the development of a product. l Check whether students understand that, before fully launching it, the prototype needs to be tested and reviewed using an iterative approach to develop it in stages until a fully functioning final product has been created. Practise (Student’s Book page 18) 1 Encourage students to discuss why it is better to develop, test and review in iterations. They can write the program requirements and pseudocode on paper or type them into a word-processed document. They should produce a table showing the variables and data types they identify in the pseudocode. Variable Data type 2 Students need access to a Python editor to create the program code to match the pseudocode. Encourage them to consider the data types and refer to their answers to task 1 to guide the program development. Remind them to save their program as pizzaChatbotV1.py. Testing should focus on ensuring that the program is functional and fulfils the program requirements identified in task 1. 3 The additional option will require the use of an extra elif and appropriate output, e.g. another pizza option to select from. The input statement also needs editing to include '4' as a choice. Students should make the changes and save their programs as pizzaChatbotV2.py. Answers 1 a Developing in iterations allows the programmer to test and gain feedback from others, which they can use to help develop the program code further. Each iteration enables the program to be developed towards the final prototype. IF selection == 1 THEN OUTPUT "Welcome to the women’s store" ELSEIF selection == 2 THEN OUTPUT "Welcome to the men’s store" ELSE OUTPUT "Welcome to the children’s store" ENDIF Sample ©Hodder Education 21

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

b The chatbot needs to: – output the options for the user to select from – allow the user to select their chosen pizza – output which pizza has been ordered. c Here is an example pseudocode algorithm. 2 For a solution, refer to pizzaChatbotV1(Teacher).py. 3 For a solution, refer to pizzaChatbotV2(Teacher).py. Review l Ask students to look at pizzaChatbotV2.py and to consider how they could reduce the number of lines of code used to present the inputs to the use. They should then to edit the program to reduce the number of lines of code, where possible, and save this version as pizzaChatbotV3.py. l The output text could be reduced further by placing it into the input line of code. l For a solution, refer to pizzaChatbotV3(Teacher).py. Homework l Provide students with 9.1.2 Worksheet 3 and ask them to look at the program code following on from the pizza-chatbot program. The worksheet asks them to describe the developments needed based on the feedback received. l For answers, refer to 9.1.2 Worksheet 3 Answers. START OUTPUT "Welcome to our pizza shop" OUTPUT "Please select from one of the following toppings" OUTPUT "1 for pepperoni" OUTPUT "2 for ham and pineapple" OUTPUT "3 for no toppings" INPUT selection IF selection == 1 THEN OUTPUT "Pepperoni pizza ordered" ELSEIF selection == 2 THEN OUTPUT "Ham and pineapple pizza ordered" ELSE OUTPUT "Margherita pizza ordered" STOP Sample ©Hodder Education 22

9.1 Presenting choices: Combining constructs

Developing in iterations Stretch: There is an opportunity for students to develop the program further in task 3 to allow users to choose between more pizza types by adding elif lines of code that match additional input options, e.g. offering the user an additional option: ‘5 for Vegan’. For a solution, refer to pizzaChatbotV2Stretch(Teacher).py. Support: It may benefit some students to have a demonstration of how the program is working in task 2. Ask one student to answer the question and hold up their option number and another student to hold up the pizza selection they have made, e.g. Student 1 holds up number 1 as the pizza selection they would make, and student 2 holds up either a picture of a pepperoni pizza or the words to show the order. This will aid understanding of what the program code is doing when it is run. Differentiation Sample ©Hodder Education 23

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

UNIT 9.1 LESSON 3

Student’s Book pages 19–23

l Code tracers

Boost online resources

l 9.1 Presentation l 9.1.3 Worksheet 4 l 9.1.3 Worksheet 4 Answers* l 9.1.3 Worksheet 5

Starter

Display 9.1 Presentation slide 2. Ask students to look at the program code and consider how they would know where an error is located if it is not an error in the syntax, e.g. How can you check the contents of a variable as it moves through the program? l The variable can be checked by tracking it through each line of code. This can help to find and fix errors and check that the program works as expected. l The error is on line 7, where the variable name has been entered incorrectly. The error would not present unless that option was selected.

l 9.1.3 Worksheet 5 Answers* l FoodSelectionChatbot.py l FoodSelectionChatbotV2(Teacher).py* l 9.1 Keywords flashcards * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks. Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the worksheets digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objectives Success criteria for students

9P.11 Use trace tables to systematically debug text-based programs. I can use a trace table to check the flow of a variable through an algorithm and a Python prototype.

Keywords

Flashcards for the following keywords are available in the Boost online resources: l flowchart l selection l pseudocode l integer l variable l string l trace table l truth table l dry run l criteriaSample ©Hodder Education

24

9.1 Presenting choices: Combining constructs

Activity notes and answers Code tracers Learn (Student’s Book page 19) l Read the ‘Learn’ box as a class to highlight how to create and use a trace table. Focus on the column headers in the table and how to add to these to include specific details relating to the algorithm or program code, e.g. the variable name or the conditional statement used in selection. l Using the example pseudocode, ensure that students can see where the column headers have been edited with the variable name and conditional statement and how the line numbers help to document each step in the algorithm or program. l Check students understand that whenever an update is made to a variable, it is added to the trace table next to the relevant line number. Practise (Student’s Book page 23) 1–2 Provide students with the program code FoodSelectionChatbot.py. Students should use the program code to complete a trace table for each input. They need to create the trace table using word-processing software. The trace table will generate an error, as all answers are outputting the same. This is the aim of the task: to find where the error is. Encourage students to complete the trace table even if they locate the error early on, as this helps to highlight the importance of trace tables. 3 Students should develop and correct the program code once they have identified the error. Ensure they save it as FoodSelectionChatbotV2.py. 4 Students should complete the trace tables again for the same four inputs used previously to check that the error has been fixed. It is important that students understand what they expect to see as the output, and discussion around this can aid understanding, e.g. if food selection 1 is added, then the expected output would be ‘If you like Pasta, look for Italian restaurants’. 5 Encourage students to discuss what integer and Boolean data types are. If required, remind them that an integer is a whole number and that Boolean data is either True or False and is generated by selection. Students should use this information to annotate their trace tables, either in writing or using word-processing software. 6 Encourage students to consider how they can use a trace table when planning their ‘Final project’, e.g. ask students how they can use a trace table to check a program. Answers 1 a Line Variable Condition Condition Condition Condition Output food food == 1 food == 2 food == 3 else 1 What type of food would you like for tea? 2 1 False 5 False 7 False 9 True 10 I am sorry I do not recognise that number! 3 Sample ©Hodder Education 25

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

b Line Variable Condition Condition Condition Condition Output food food == 1 food == 2 food == 3 else 1 What type of food would you like for tea? 2 2 3 False 5 False 7 False 9 True 10 I am sorry I do not recognise that number! c Line Variable Condition Condition Condition Condition Output food food == 1 food == 2 food == 3 else 1 What type of food would you like for tea? 2 3 3 False False 7 False 9 True 10 I am sorry I do not recognise that number! d Line Variable Condition Condition Condition Condition Output food food == 1 food == 2 food == 3 else 1 What type of food would you like for tea? 2 4 3 False 5 False 7 False 9 True 10 I am sorry I do not recognise that number! 2 The error is that whatever the input, the output is always ‘I am sorry I do not recognise that number!’. The conditional statements are all false, and only the else is true. The error is in the input as it is not being stored as an integer. The program code needs to be edited to include the int() code. 3 For a solution, refer to FoodSelectionChatbotV2(Teacher).py. 5 Sample ©Hodder Education 26

9.1 Presenting choices: Combining constructs

4 Input = 1 Line Variable Condition Condition Condition Condition Output food food == 1 food == 2 food == 3 else 1 What type of food would you like for tea? 2 1 3 True 4 If you like Pasta, look for Italian restaurants Input = 2 Line Variable Condition Condition Condition Condition Output food food == 1 food == 2 food == 3 else What type of food would you like for tea? 2 2 3 False 5 True 6 If you like Noodles, look for Chinese restaurants Input = 3 Line Variable Condition Condition Condition Condition Output food food == 1 food == 2 food == 3 else 1 What type of food would you like for tea? 2 3 3 False 5 False 7 True 8 If you like Chicken Tikka, look for Indian restaurants 1 Sample ©Hodder Education 27

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Input = 4 Line Variable Condition Condition Condition Condition Output food food == 1 food == 2 food == 3 else 1 What type of food would you like for tea? 2 4 False 5 False 7 False 9 True 10 I am sorry I do not recognise that number! 5 The integer is where the numbers 1, 2, 3, 4 are input and stored in the variable ‘food’. The Boolean data type is the output to each conditional statement if, elif and else. 6 Trace tables can be used to check the content of variables through a program to make sure that the program works as expected and to find any errors that need to be debugged. Review l Provide 9.1.3 Worksheet 4 and ask students to look at the Python code and complete the trace table. l For answers, refer to 9.1.3 Worksheet 4 Answers. Homework l Provide 9.1.3 Worksheet 5. Ask students to complete the trace table for the Python program. l For answers, refer to 9.1.3 Worksheet 5 Answers. Code tracers Stretch: There is an opportunity for students to justify why an integer is used instead of a string for the input, following task 2, e.g.: An integer means that the input from the user can be compared easily in the conditional statements; if the input is a string, it could be entered with or without uppercase letters or spelled incorrectly, which could result in the program producing the wrong output. Support: It may benefit some students to talk through the program in task 1a, using a pen and paper or whiteboard to write down the values stored in the variables and document where and when they change. Working through the first example in this way should give students the confidence to work through the remaining values with a partner. Differentiation 3 Sample ©Hodder Education 28

9.1 Presenting choices: Combining constructs

UNIT 9.1 LESSON 4

Student’s Book pages 23–28

l Error processing

Boost online resources

l Trace templates.docx l 9.1.4 Worksheet 6 l 9.1.4 Worksheet 6 Answers* l 9.1.4 Worksheet 7 l 9.1.4 Worksheet 7 Answers* l StudentScoreChatbot.py

Starter

l Ask students to discuss with their partners the ways in which they have found errors in program code they have created in previous stages. Encourage students to consider how easy it is to find and fix errors, e.g. a message is displayed to show which line an error is on, or testing shows that the program output is not as expected. l Ask students to recall what trace tables are used for: e.g. a trace table is used when creating an algorithm for following a variable from the start of an algorithm through to the end, and shows where it is input, processed and output.

l StudentScoreChatbotV2(Teacher).py* l StudentScoreChatbotV3(Teacher).py* l StudentScoreChatbotV4(Teacher).py* l 9.1.4 Visual 2 l 9.1 Keywords flashcards * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks. Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the worksheets digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objective Success criteria for students

9P.06 Use iterative development on software prototypes to produce solutions to problems. I can use iterative development on Python prototypes to create solutions to problems. 9P.10 Identify a range of errors, including syntax, logic and runtime errors. I can identify and describe a range of errors, including syntax, logic and runtime errors. 9P.11 Use trace tables to systematically debug text-based programs. I can use a trace table to check the flow of a variable through an algorithm and a Python prototype.

Keywords

Flashcards for the following keywords are available in the Boost online resources: l logic error l syntax error l runtime error l conditional operator l conditional statementSample ©Hodder Education

29

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

l Share 9.1.4 Visual 2 with students and ask what they can learn from this program-error example. (The error generated is a syntax error; it is an error in the way the program code has been written.

It tells you the error is on line 1 and points out that the error is the bracket following the word

‘print’. The error message helps the programmer debug the program code of syntax errors.)

Activity notes and answers

Error processing Learn (Student’s Book page 23) l Start by recapping the learning from the previous lesson, looking at trace tables and how they are used to follow a variable through a program and document how its value changes. l Read the ‘Learn’ box as a class. Focus on the differences between the three different types of errors that can be produced in a program: syntax, logical and runtime. l Demonstrate the example to show the class how the trace table is completed from the pseudocode example. Emphasise how this trace table can identify the logical error and how the pseudocode can be adjusted to fix it. l Check that students understand the differences between logical, syntax and runtime errors. Practise (Student’s Book page 28) 1 a Provide students with StudentScoreChatbot.py. Explain that running the program will provide with guidance on the syntax error. b Remind students to save the updated program as StudentScoreChatbotV2.py. 2 Students need to create trace tables for this task either electronically or on paper. The inputs are provided, and students need to create four trace tables to test the program with a range of inputs. 3 a Explain to students that they need to use the trace tables to identify a logical error and annotate where they find the error. b Remind students to save the updated program as StudentScoreChatbotV3.py. 4 a Students need to recreate the trace tables they used in task 2, and then compare the completed trace tables to find the differences and see where the error is located and the impact it has on the output. Explain that they now need to use the trace tables to identify a runtime error, and discuss where the error is found. b Remind students to save the updated program as StudentScoreChatbotV4.py. 5 Encourage students to discuss the different ways in which they identified the errors, how the

Python platform helped and where a trace table helped. Explain that using trace tables is a process available to programmers to help find and fix errors. Encourage students to discuss the benefits of using trace tables. Answers 1 b For a solution, refer to StudentScoreChatbotV2(Teacher).py.

2 a Line Variable Condition Condition Condition Condition Output score score >= 90 score <= 51 and score <= 89 score >= 20 and score <= 50 else

2 95 True 4 You are working at a Distinction level. 5 Keep the focus on new subject areas. 3 Sample ©Hodder Education 30

9.1 Presenting choices: Combining constructs

b Line Variable Condition Condition Condition Condition Output score score >= 90 score <= 51 and score <= 89 score >= 20 and score <= 50 else

2 15 3 False 6 True 7 You are working at a Merit level. You are doing well. Focus on revision techniques.

c Line Variable Condition Condition Condition Condition Output score score >= 90 score <= 51 and score <= 89 score >= 20 and score <= 50 else

2 25 3 False 6 True 7 You are working at a Merit level. 8 You are doing well. Focus on revision techniques.

d Line Variable Condition Condition Condition Condition Output score score >= 90 score <= 51 and score <= 89 score >= 20 and score <= 50 else

2 80 3 False 6 True 7 You are working at a Merit level. 8 You are doing well. Focus on revision techniques. 3 a The logical error is with the second conditional statement as it is set to less than or equal to 51 and less than or equal to 89. This causes the conditional statements to be either True or False at incorrect times. b For a solution, refer to StudentScoreChatbotV3(Teacher).py. 8 Sample ©Hodder Education 31

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

4 a Trace table with input = 95.

Line Variable Condition Condition Condition Condition Output score score >= 90 score >= 51 and score <= 89 score >= 20 and score <= 50 else

2 95 3 True 4 You are working at a Distinction level. 5 Keep the focus on new subject areas. Trace table with input = 15.

Line Variable Condition Condition Condition Condition Output score score >= 90 score >= 51 and score <= 89 score >= 20 and score <= 50 else

2 15

False 6 False 9 False 12 True 13 You have not passed this assessment. 14 Some one-toone time would help with looking at content. Trace table with input = 25.

Line Variable Condition Condition Condition Condition Output score score >= 90 score >= 51 and score <= 89 score >= 20 and score <= 50 else

2 25 3 False 6 False 9 Traceback error 3 Sample ©Hodder Education 32

9.1 Presenting choices: Combining constructs

Trace table with input = 80.

Line Variable Condition Condition Condition Condition Output score score >= 90 score >= 51 and score <= 89 score >= 20 and score <= 50 else

2 80 3 False True 7 You are working at a Merit level. 8 You are doing well. Focus on revision techniques. b For a solution, refer to StudentScoreChatbotV4(Teacher).py. 5 The Python editor will not run if there is a syntax error and it will generate an error message that is visible to the programmer, indicating what the problem is. This means that syntax errors can be identified more quickly than logical or runtime errors. The use of trace tables helps to identify any logical or runtime errors as they would not be found without thorough testing. Review l Provide students with 9.1.4 Worksheet 6. Ask them to read the scenario and complete the trace table for the prototype Python program to find the logical errors. l For answers, refer to 9.1.4 Worksheet 6 Answers. Homework l Provide students with 9.1.4 Worksheet 7. Ask them to complete the sentences with the correct type of error and justify why a programmer should use trace tables. l For answers, refer to 9.1.4 Worksheet 7 Answers. Error processing Stretch: There is an opportunity during task 5 for students to present their findings and the process they went through to identify the syntax, logical and runtime errors. This allows students to justify the importance of testing and the benefit of trace tables to this process. Support: It may help some students to have the trace tables set up ready for them to complete for tasks 2, 3, and 4. Provide students with Trace templates.docx, which has the trace tables set up and the line numbers inserted, to support students with completing these tasks. Differentiation 6 Sample ©Hodder Education 33

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

UNIT 9.1 LESSON 5

Student’s Book pages 28–35

l Iteration introduction l Iteration in algorithms

Boost online resources

l 9.1 Presentation l 9.1.5 Worksheet 8 l 9.1.5 Worksheet 8 Answers* l 9.1.5 Worksheet 9 l 9.1.5 Worksheet 9 Answers* l forLoopExample.py l CountdownChatbotStart(Teacher).py* l countdown10-1(Teacher).py* l timesTable(Teacher).py* l FoodSelectionChatbotV2.py (students’ file from Lesson 3) l FoodSelectionChatbotV3(Teacher).py* l FoodSelectionChatbotStretch(Teacher).py* l 9.1 Keywords flashcards * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks.

Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the worksheets digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objective Success criteria for students

9CT.02 Follow flowchart or pseudocode algorithms that use loops. I can follow flowchart or pseudocode algorithms that use loops. 9CT.06 Understand and use iteration statements, limited to count-controlled loops, presented as either flowcharts or pseudocode. I can explain and use iteration statements with count-controlled loops in either pseudocode or flowcharts. 9CT.07 Predict the outcome of algorithms that use iteration. I can evaluate the processes that are followed to develop programs. 9CT.08 Compare and contrast algorithms designed for the same tasks to determine which is best suited to the purpose. I can compare and contrast two algorithms for the same solution and decide which is best suited to the task. 9P.03 Know how to develop text-based programs with count-controlled loops. I can predict the outcome of algorithms that use iteration.

Keywords

Flashcards for the following keywords are available in the Boost online resources: l sequence l for loop l selection l loop variable l execute l efficient l iterate/iterative/iteration l count-controlled loopSample ©Hodder Education

34

9.1 Presenting choices: Combining constructs

Starter l Display 9.1 Presentation slide 3. Ask students to read Instruction 1 and follow it (clap their hands once, clap their hands once, clap their hands once). l Ask students to read Instruction 2 and follow it (clap their hands three times and stop). l Ask students the difference between the instructions (the instructions are the same, but the second set of instructions asks for the same instruction to be repeated three times, instead of writing the instruction out individually three times). l Explain that there are times in programs such as chatbots when instructions or questions need to be asked more than once. The use of a loop can save time for the programmer, as the same instruction is not written out more than once; it is set to run a set number of times. Activity notes and answers Iteration introduction Learn (Student’s Book page 28) l Read the ‘Learn’ box as a class. Focus on the structure of a count-controlled loop and use forLoopExample.py to demonstrate the code in the ‘Learn’ box, which shows the output and the iteration number. l Explain how a count-controlled loop can be used in a chatbot to ask a question more than once, and how selection can be indented inside the for loop. Demonstrate this on the teacher computer. l Check students understand that a count-controlled loop is used to repeat instructions a set amount of times. Practise (Student’s Book page 30) 1 Students need the Python program they created in the previous lesson that they saved as FoodSelectionChatbotV2.py. Encourage them to consider which lines of code would need to be indented inside a count-controlled loop to allow it to be run twice. 2 Students need to consider where instructions are being repeated to identify where to add a count-controlled loop. Once they have made changes to the program code by adding a count-controlled loop, they need to save their new development iteration as FoodSelectionChatbotV3.py. Answers 1 The question asking the user to input and the selection need to be indented inside a for loop set to run twice. 2 For a solution, refer to FoodSelectionChatbotV3(Teacher).py. Iteration in algorithms Learn (Student’s Book page 31) l Read the ‘Learn’ box as a class. Focus on the difference between the flowcharts with and without a count-controlled loop and the pseudocode with and without a count-controlled loop. l Discuss how a count-controlled loop can help to reduce the number of lines of code, and how this makes the code more efficient. l Check that students understand how a count-controlled loop is represented in the flowchart and pseudocode. Sample ©Hodder Education 35

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Practise (Student’s Book page 34) 1–2 Students should work in pairs to discuss each pseudocode example. Encourage students to talk through each pseudocode example to identify the flow, e.g. identifying that this is an example of two algorithms that have been designed for the same output. 3 Students should work in pairs. Remind them that comparing is looking for similarities and/or differences, and contrasting involves comparing to find the differences. 4 Remind students that efficiency in program code is defined by the lack of repetition of lines of code and the effective use of selection and iteration. 5 Students should create a variable and data-type table in word-processing software or in writing. Remind them that they are focusing on pseudocode example 2 with the countcontrolled loop. 6 Students should create a program that matches pseudocode example 2 with the countcontrolled loop and save it as CountdownChatbotStart.py. Remind them of the importance of the colon and indentation in writing the for loop. 7 Students should use word-processing software or on paper. Remind them of the importance of the column headings and how these are linked to the variables being used; ‘i’ for counting the iterations and ‘countdown’ for storing the number/integer. 8 Encourage students to discuss in pairs how the use of a count-controlled loop could benefit a user at the start of a program. Encourage discussion with the following questions: – When do you know that a chatbot or program has started? – Would a countdown help to get you ready to answer questions? Answers 1 The prediction should be that both the program outputs would count down from 3 to 1 and then say ‘Let’s start’, with a 1-second delay between each output. 2 A chatbot could use a loading-style countdown to the first question as a loading start or to get the user ready to start talking to the chatbot. 3 Pseudocode example 1 imports the 'time' library and sets up a variable called ‘countdown’ that is output and then reduced by 1, output and reduced by 1, output and reduced by 1, and then outputs ‘Let’s start’. The output displayed is: ‘3, 2, 1. Let’s start’. Pseudocode example 2 imports the ‘time’ library and sets up a variable called ‘countdown’. A count-controlled loop is used to iterate over the output and reduction of the variable value by 1. The loop will iterate three times and then output the text ‘Let’s start’. Similarities Differences Both algorithms produce the same output Algorithm 1 uses only sequence; algorithm 2 uses a count-controlled loop Both algorithms use the ‘time’ library The countdown has an initial value of 3 in algorithm 1 and 4 in algorithm 2 Algorithm 2 includes a count variable ‘i’ 4 The second example is more efficient, as the count-controlled loop iterates over two instructions, reducing the number of lines of code. The first example takes longer to create as more lines of code are needed. Sample ©Hodder Education 36

9.1 Presenting choices: Combining constructs

5 Variable Data type countdown integer i integer 6 For a solution, refer to CountdownChatbotStart(Teacher).py. 7 For example: Line Variable Variable Output i countdown 3 5 0 6 3 5 1 6 2 5 2 6 1 9 Let’s start 8 For example: A countdown is a good way to start a program or chatbot. It acts like an introduction before the user starts to play a game or answer questions. – When do you know that a chatbot or program has started? Some chatbots go straight into ‘Hello’, and if the user does not answer quickly there is a timer that prompts them to answer or check that they are still there. Having a structured start could help users. – Would a countdown help to get you ready to answer questions? At the start, it may help users to know when the questions are about to begin by giving them a visual prompt with a countdown. Review l Provide students with 9.1.5 Worksheet 8 and ask them to complete the questions about countcontrolled iteration. Students need access to a Python editor to complete the tasks. l For answers, refer to 9.1.5 Worksheet 8 Answers and timesTable(Teacher).py. Homework l Provide students with 9.1.5 Worksheet 9 and ask them to look at the pseudocode and identify the variables, data types, output from an input, and how the number of iterations is defined in this program. l For answers, refer to 9.1.5 Worksheet 9 Answers. 4 Sample ©Hodder Education 37

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Iteration introduction Stretch: There is an opportunity following task 2 to add to the program a ‘thank you’ line of code that is run after the count-controlled loop has been completed. For a solution, refer to FoodSelectionChatbotStretch(Teacher).py. Support: It may benefit some students to have additional support in task 2 when creating the count-controlled loop. Write down the possible outputs for the food selection on pieces of paper and give them to one student. Ask the student to act as the chatbot and to ask you for your food selection; then give your choice and have the student hold up the piece of paper with the output that is linked to the answer. Repeat this process to demonstrate the count-controlled loop. Discuss with students how they would know how many times to ask for the food selection (the number set on the for loop). Also ask how they knew which piece of paper to hold up (they made the decision based on the food selection; this is what selection does). Iteration in algorithms Stretch: There is an opportunity following task 6 for students to edit the program code to increase the countdown to start from 10 and finish at 1. For a solution, refer to countdown10-1(Teacher).py. Support: Some students may need additional support in task 7 when completing the trace table. They may benefit from a written, on paper or whiteboards, that shows how the contents stored in the variables change. Highlight that the variable ‘i’ is increasing with each iteration starting from 0. Differentiation Sample ©Hodder Education 38

9.1 Presenting choices: Combining constructs

UNIT 9.1 LESSON 6

Student’s Book pages 35–38

l Iterations and arrays

Boost online resources

l 9.1 Presentation l 9.1.6 Worksheet 10 l 9.1.6 Worksheet 10 Answers* l 9.1.6 Worksheet 11

l 9.1.6 Worksheet 11 Answers* l iceCreamFlavoursChatbot(Teacher).py* l rainbowColoursChatbotV1(Teacher).py* l 9.1 Keywords flashcards * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks. Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the worksheets digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objective Success criteria for students

9CT.02 Follow flowchart or pseudocode algorithms that use loops. I can follow flowchart or pseudocode algorithms that use loops. 9CT.07 Predict the outcome of algorithms that use iteration. I can predict the outcome of algorithms that use iteration. 9P.01 Explain the purpose of a one-dimensional array. I can identify and explain the purpose of a onedimensional array. 9P.03 Know how to develop text-based programs with count-controlled loops. I can develop a Python program with countcontrolled loops. 9P.04 Know how to access data from an array using a text-based language. I can access data from an array using Python.

Keywords

Flashcards for the following keywords are available in the Boost online resources: l array l list

l data itemSample ©Hodder Education

39

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Starter l Display 9.1 Presentation slide 4. Ask students what a list is and where they have used lists before, e.g. shopping lists, to-do lists, debugging checklists, project-requirement checklists. l Point out that lists store more than one item, e.g. a shopping list has more than one item for purchase. l Ask students where, at present, they store items in a Python program (in a variable, and it can store one item). l Ask students how they have stored multiple items in a Python program before (by creating multiple variables, each with its own name and storing one item). l Explain that there is another type of storage that can be used in a program, which is called an array, and another word for this is a list as it can store more than one item. Activity notes and answers Iterations and arrays Learn (Student’s Book page 35) l Read the ‘Learn’ box as a class. Demonstrate on the teacher computer how to set up an array in Python. l Focus on how you can use a for loop to iterate through the items in a list. l Demonstrate how you can use a for loop to add a set number of items to a list. l Check students understand that a list can store more than one item, compared with a variable, which can store only one item. Practise (Student’s Book page 37) 1–2 Students should work in pairs to discuss the pseudocode. Use the questions in the ‘Practise’ box to structure the discussion, and encourage students to analyse the pseudocode for the loop and list. 3 Students need to create the program that matches the pseudocode and save it as rainbowColoursChatbotV1.py. Remind students that to add an item to an array they need to ‘append’ it, and that this code needs to be indented in the for loop to allow each answer to be added to the array. 4 Students could document the specific output they expect to see along with the actual output to check that the program works as expected. 5 Encourage students to consider what is stored in the array and how a count-controlled loop is used to access each item in turn to print it out. Answers 1 a red, orange b Five times c The output will be “Your rainbow colours are: Red orange …” followed by the 4 colours the user enters when prompted. d To break up the inputs and the outputs e red, orange, yellow, green, blue, indigo, violet 2 For example: -----------------------------------Your rainbow colours are: red orange Sample ©Hodder Education 40

9.1 Presenting choices: Combining constructs

yellow green blue indigo violet 3 For a solution, refer to rainbowColoursChatbotV1(Teacher).py. 4 Students should find that their output prediction in task 2 is replicated when the program is run. 5 The array is used to store all the colours in the program. A count-controlled loop is used to access each colour in turn and print it out. Review l Provide students with 9.1.6 Worksheet 10 and ask them to look at the pseudocode to answer the questions and create the Python program. l For answers, refer to 9.1.6 Worksheet 10 Answers. Homework l Provide students with 9.1.6 Worksheet 11 and ask them to complete the sentences with the missing words. l For answers, refer to 9.1.6 Worksheet 11 Answers. Iterations and arrays Stretch: There is an opportunity in task 1 for students to lead the discussion and demonstrate how to locate the answers for each question, e.g. by using the teacher computer to demonstrate the code to add an item to the array. This allows students to extend their knowledge by explaining the process for answering the questions linked to the pseudocode. Ask students how they would edit the code to allow another colour to be added to the array (increase the number of iterations in the for loop from 5 to 6). Support: It may benefit some students to work through the questions in task 1 as a class or in a group, to demonstrate together the process of working through each question and identifying where the answers are located, e.g. the content of the array at the start of the program means identifying where the array is defined and what is inside the square brackets. Differentiation Sample ©Hodder Education 41

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

UNIT 9.1 LESSON 7

Student’s Book pages 38–45

l Developing the chatbot further

Boost online resources

l 9.1 Presentation l 9.1.7 Worksheet 12 l 9.1.7 Worksheet 12 Answers* l Pseudocode.docx

Starter

l Display 9.1 Presentation slide 5. Ask students to identify where the program code uses selection and count-controlled iteration. Slide 6 shows the two areas labelled. l Using slide 6, ask students to identify: – the input (food = int(input…) – an output in the program code (print()) – how many times the loop will iterate (two)

l ActivitiesChatbot.py l ActivitiesChatbotV2(Teacher).py* l ActivitiesChatbotV3(Teacher).py* l Keyword flashcard * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks. Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the worksheets digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objective Success criteria for students

9CT.03 Know how to create algorithms using flowcharts and pseudocode. I can create algorithms using flowcharts and pseudocode. 9CT.09 Combine multiple constructs (sequence, selection, count-controlled iteration) to write algorithms as flowcharts or pseudocode. I can create an algorithm as a flowchart or pseudocode using more than one construct: sequence, selection and count-controlled iteration. 9P.01 Explain the purpose of a one-dimensional array. I can identify and explain the purpose of a onedimensional array. 9P.06 Use iterative development on software prototypes to produce solutions to problems.

I can use iterative development on Python prototypes to create solutions to problems. Keyword A flashcard for the following keyword is available in the Boost online resources: l one-dimensional array Sample ©Hodder Education 42

9.1 Presenting choices: Combining constructs

– the data type the variable is stored as (integer) – which lines of code are displayed before and after the input and selection (print("What type of food would you like for tea?"), print("Thank you for your selections")). Activity notes and answers Developing the chatbot further Learn (Student’s Book page 38) l Read the ‘Learn’ box as a class. Focus students on understanding the key concepts and how they are demonstrated in a flowchart and pseudocode. It may benefit students to compare the flowcharts and pseudocode throughout the ‘Learn’ box to see how they are developed iteratively. l Focus on talking through the use of arrays and how the data is accessed from the arrays using the position number. l Discuss how a program is developed based on the initial requirements, but can be developed iteratively as the program is tested and reviewed. l Check that students understand the importance of the different programming concepts (sequence, selection and iteration) in the development of any program, and how these enable it to evolve from algorithm to program. Practise (Student’s Book page 44) 1 Students should consider what additional items could be added to the program’s arrays to expand the program further, and the structure of the additional activity when added to the array. Students need to add a new item to each array. 2 Students need to create the pseudocode for the new development iteration either electronically or on paper. With the addition of more items in the array, students need to consider the selection statements to ensure that there is an output if the user selects 1, 2 or 3 when prompted. Students also need to consider the number of iterations in the for loop, so that all options are displayed to the user. 3 Students need to work in pairs to compare and contrast their pseudocode. They need to create a trace table on word-processing software or paper to test each other’s pseudocode. Remind students that comparing is looking for similarities and/or differences, and contrasting is comparing to show the differences, e.g. ‘both programs have for loops’ is comparing; ‘student 1 has a for loop that iterates twice and student 2 has a for loop that iterates three times’ is contrasting. 4 Students need ActivitiesChatbot.py to develop the program code to add the new activities. Students should not change the main structure of the original program; they are adding the additional array items and additional conditional statements to the program using elif to accommodate the additional items. Remind students to save this as ActivitiesChatbotV2.py. 5 a Encourage students to consider how selection would be used to ask further follow-on questions, each depending on the previous answer. b Students should consider how one-dimensional arrays can be used to provide a list of options for the user to choose between.Sample ©Hodder Education 43

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Answers 1 At least one extra activity needs to be added into each array. 2 Here is one possible solution. 1 START 2 ARRAY water = [Swimming, Canoeing, Windsurfing] 3 ARRAY team = [Hockey, Volleyball, Netball] 4 ARRAY waterNew = [Water polo, Sailing, Paddleboarding] 5 ARRAY teamNew = [Cricket, Beach volleyball, Basketball] 6 OUTPUT "Do you prefer watersports or team games?" 7 INPUT typeOfActivity 9 IF typeOfActivity == "W" THEN 10 OUTPUT "Which of the following watersports do you prefer?" 11 FOR i = 0 to 2 12 OUTPUT i + 1, water[i] 13 OUTPUT "Enter the number of your preferred activity" 14 INPUT activity1 15 OUTPUT "You have chosen" activity1 16 17 IF activity1 == 1 THEN 18 OUTPUT "Why not try" waterNew[0] 19 ELSEIF activity1 == 2 THEN 20 OUTPUT "Why not try" waterNew[1] 21 ELSE 22 OUTPUT "Why not try" waterNew[2] 23 ENDIF 24 25 ELSE 26 OUTPUT "Which of the following team games do you prefer?" 27 FOR i = 0 to 2 28 OUTPUT i + 1, team[i] 29 OUTPUT "Enter the number of your preferred activity" 30 INPUT activity2 31 OUTPUT "You have chosen" activity2 8 Sample ©Hodder Education 44

9.1 Presenting choices: Combining constructs

3 Students’ comparisons will differ depending on their pseudocode. Each student should consider why they created their pseudocode the way they did, and discuss the similarities and differences.

Comparisons should identify similarities and differences; contrasting should back up the similarities and/or differences with specific details, e.g. the position numbers of the array used are different.

The trace table below shows one flow through the program using the following inputs: team, Hockey

Line Array Array Array Array Variable Condition Variable Variable Condition Output water team waterNew teamNew typeOf Activity typeOf Activity == "W"

i activity2 activity2 == 1 2 Swimming Canoeing Windsurfing 3 Hockey Volleyball Netball Water polo Sailing Paddleboarding 5 Cricket Beach volleyball Basketball 6 Do you prefer watersports or team games? 7 team 9 False 32 33 IF activity2 == 1 THEN 34 OUTPUT "Why not try" teamNew[0] 35 ELSEIF activity2 == 2 THEN 36 OUTPUT "Why not try" teamNew[1] 37 ELSE 38 OUTPUT "Why not try" teamNew[2] 39 ENDIF 40 41 ENDIF 42 STOP 4 Sample ©Hodder Education 45

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Line Array Array Array Array Variable Condition Variable Variable Condition Output water team waterNew teamNew typeOf Activity typeOf Activity == "W" i activity2 activity2 == 1

26 Which of the following team games do you prefer? 28 Hockey 28 1 Volleyball 28 2 Netball 29 Enter the number of your preferred activity 30 1 31 You have chosen Hockey 33 True 34 Why not try Cricket 4 For a possible solution, refer to ActivitiesChatbotV2(Teacher).py. 5 a For example: Selection enables the next question a chatbot asks to vary depending on the answer to the previous question. If selection was not used, then the chatbot would always ask exactly the same questions in exactly the same order. b Each one-dimensional array (list) in this chatbot program stores the different options for a particular type of activity.

Review

l Ask students to consider what would happen if the user did not enter their choice as expected when asked for their preferred activities in their last development of the activities chatbot

ActivitiesChatbotV2.py. l Ask: How could the program prototype be developed further in another iteration to ensure that the user receives a message to advise them that they have entered an invalid choice?

Students should develop their Python programs and save their development iterations as

ActivitiesChatbotV3.py. l Remind students that the user should always be asked to enter their choice as an integer. This will avoid problems with upper/lowercase or misspelling. l For a solution, refer to ActivitiesChatbotV3(Teacher).py.

Homework

l Provide students with 9.1.7 Worksheet 12 and ask them to look at the program code, identify where the key programming concepts are located and answer the questions. l For answers, refer to 9.1.7 Worksheet 12 Answers.

0 Sample ©Hodder Education

46

9.1 Presenting choices: Combining constructs

Developing the chatbot further Stretch: There is an opportunity in task 4 for students to share their program development with others in the class and describe how they have arrived at their solution. This gives students the opportunity to showcase their understanding by explaining and justifying their own program development. Students could also discuss how the program would need to be developed if the chatbot needed to include a new type of sport ‘air sports’ (a new array would need to be created, with ‘air sports’ and additional options added to the program to allow the user to select and output in the same way as the other sport options). Support: Some students may benefit from receiving the existing pseudocode for task 2, which they can annotate to show the new developments, rather than writing the whole pseudocode algorithm from scratch. Provide these students with Pseudocode.docx. Differentiation Sample ©Hodder Education 47

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

UNIT 9.1 LESSON 8

Student’s Book pages 45–48

l Testing times

Boost online resources

l 9.1 Presentation l 9.1.8 Worksheet 13 l 9.1.8 Worksheet 13 Answers* l 9.1.8 Worksheet 14 l 9.1.8 Worksheet 14 Answers* l TestProgram.py l TestProgramV2(Teacher).py*

l TestProgramV3(Teacher).py* l travelChatbotV1.py l travelChatbotV2(Teacher).py* l syntaxErrorExample.py l runtimeErrorExample.py l 9.1 Keywords flashcards * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks. Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the worksheets digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objective Success criteria for students

9P.08 Know how to develop and apply test plans that include normal, extreme and invalid data. I can develop and apply test plans that include normal, extreme and invalid data. 9P.09 Identify test data that covers normal, extreme and invalid data. I can identify test data that covers normal, extreme and invalid data. 9P.10 Identify a range of errors, including syntax, logic and runtime errors. I can identify and describe a range of errors, including syntax, logic and runtime errors.

Keywords

Flashcards for the following keywords are available in the Boost online resources: l syntax error l traceback message l integrated development environment (IDE) l normal test data l logic error l extreme test data l conditional operator l invalid test data l runtime errorSample ©Hodder Education

48

9.1 Presenting choices: Combining constructs

Starter l Display 9.1 Presentation slide 7. Ask students to identify the errors in the code. The errors are syntax errors in how the code has been written. There are seven errors within the chatbot code for the ice cream selection program. l Slide 8 has the seven areas circled. l Ask students how they know when there is a syntax error – an error in the way the program is written (the program will not run and it generates an error message for the programmer to investigate and fix). Activity notes and answers Testing times Learn (Student’s Book page 45) l Read the ‘Learn’ box as a class. Focus students on the three different types of errors that can be found in program code. Demonstrate the following programs on the teacher computer to match the Student’s Book examples: – syntaxErrorExample.py links with the first program code in the ‘Learn’ box – runtimeErrorExample.py links with the program code in the table in the ‘Learn’ box. l Discuss how the programmer knows that an error has been found, e.g. the error message that appears at the start for a syntax error, and when it is encountered for a runtime error. Remind students of the lessons containing the trace tables and how they helped to identify logical errors in the conditional statements. l Check students understand that a syntax error generates an error immediately when you try to run the program, a logical error allows the program to run but will not give the expected outputs, and a runtime error generates a traceback error when the problem line of code is executed in the program. Practise (Student’s Book page 48) 1 Provide students with TestProgram.py and ask them to identify suitable test data. Encourage them to use a range including normal, extreme and invalid data. It is important that students run the program and complete the test plan, even if they see the errors first. Encourage them to look at the error messages to identify and fix the errors. Students should debug and fix the program code and save it as TestProgramV2.py. 2 Ensure that students understand the importance of using a wide range of test data to find and fix the range of possible errors. Check that they understand the benefits of normal, invalid and extreme test data in a test plan. 3 Encourage discussion by asking students to consider which type of error presents itself to the programmer first and why. Which error might be the last type a programmer finds? Why? 4 Emphasise to students that test plans are a process that programmers use to facilitate the development of the program code. Ask them to evaluate the importance of test plans linked with test data and types of errors, e.g. Would a logical error be found without using a full range of test data? Answers 1 a Extreme test data does not work on this program as the inputs can be anything. Normal test data would be adding and using pizza toppings, e.g. ham, pepperoni and mushroom. Invalid test data would be an option that had not been added at the start of the program, e.g. ‘sausage’. Sample ©Hodder Education 49

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

b–c This is an example showing test data.

Test Test data Expected outcome Pass/fail

Normal pizzaToppings = ham, pepperoni, mushroom input Output as contents of array Normal decision = Pepperoni Output: You can have double that topping! Fail Invalid decision = Sausage Not accepted Fail: You can have double that topping! d For a solution, refer to TestProgramV2(Teacher).py.

e Test Test data Expected outcome Pass/fail

Normal pizzaToppings = ham, pepperoni, mushroom input Output as contents of array Normal decision = Pepperoni Output: You can have double that topping!

Pass Invalid decision = Sausage Not accepted Pass 2 Testing a program with a wide range of data is essential to help find and fix all types of errors. The different types of test data help to find different types of errors, e.g. the invalid test data highlighted the logical error as it would not have been found in the array. This shows that the error was the comparison operator !=, which should have been ==. This could also have been identified using a trace table. 3 – A syntax error is when the code has been added incorrectly and stops the program running until it is fixed. This type of error is identified first as the program will not run. – A runtime error is when the program starts correctly but an error is found as the program code is run. This is found through test plans using a range of test data; the program will stop running and the error will be located with a traceback message, including information to help find and fix it. – A logical error is when the program will run but the output is not as expected if the wrong operator has been used. A trace table would help to find and fix this error as it may be linked with how a conditional statement uses a comparison operator. The other way in which a logical error may be found is through using invalid and extreme test data, as this would test the range of inputs in the program. 4 A test plan is an essential process for a programmer, and without it some errors, such as a logical error, may not be detected. If the prototype program is not tested fully, the final program could be released and not work as it is supposed to. Review l Provide students with travelChatbotV1.py and 9.1.8 Worksheet 13. Ask students to run the program to find and fix the errors. The program contains syntax errors, a logical error and a runtime error. Once students have debugged the program and it is error-free, they should save it as travelChatbotV2.py. l For a solution, refer to travelChatbotV2(Teacher).py and 9.1.8 Worksheet 13 Answers.Sample ©Hodder Education 50

9.1 Presenting choices: Combining constructs

Homework l Provide students with 9.1.8 Worksheet 14. Ask them to read the words and use them to fill in the gaps, reviewing the different types of errors and test data by adding the correct keyword to each paragraph. l For answers, refer to 9.1.8 Worksheet 14 Answers. Testing times Stretch: There is an opportunity in task 1 for students to consider how the program tells the user that the input is invalid, as they are still told to enjoy the pizza, e.g. How could they use else to complete the final lines of code and also move the code on line 14? For a solution, refer to TestProgramV3(Teacher).py. Support: For task 1, it may benefit some students to discuss the possible inputs that could be used as normal test data, e.g. ask students to select three toppings for the pizza and use these as the normal test data. Explain that there is no extreme test data for this test plan as the toppings array could accept any input. Working through the creation of the test-plan and carrying out the testing with another student can enable discussion and support through this process. Differentiation Sample ©Hodder Education 51

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

UNIT 9.1 LESSON 9

Starter

l Ask students, in pairs, to write down all the different ways in which they could enter the word

‘Python’, considering upper and lowercase letters, e.g.: – python – PYTHON – Python – PYthon – PYThon – PYTHon – PYTHOn – PyThOn l Ask students how a chatbot program would know how a user is going to answer a question (there is no way of knowing completely, and the program would not be able to accommodate all possible combinations as an input). l Explain that the solution is for the program to change whatever is input into a specific format for the rest of the program to understand, e.g. changing any of the ways of entering ‘Python’ listed above to all lowercase letters (‘python’).

Student’s Book pages 49–52

l Go further l Challenge yourself

Boost online resources

l RainbowColoursChatbot.docx l rainbowColoursChatbotV1.py (Students’ file from Lesson 6) l rainbowColoursChatbotV2(Teacher).py* l rainbowColoursChatbotV3(Teacher).py*

l stringManipulation.py l stringManipulation(Teacher).py* l challengeYourself(Teacher).py* l stringManipulationExamples.py l Keyword flashcard * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks. Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the worksheets digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objective Success criteria for students

9CT.01 Follow, understand, edit and correct algorithms that are presented as pseudocode. I can follow, understand, edit and correct algorithms that are presented as pseudocode. 9P.05 Know how to develop text-based programs using string manipulation, including length, uppercase and lowercase.

I can develop Python programs using string manipulation, including length, uppercase and lowercase. Keyword A flashcard for the following keyword is available in the Boost online resources: l string manipulation Sample ©Hodder Education 52

9.1 Presenting choices: Combining constructs

Activity notes and answers

Go further (Student’s Book page 49) 1–2 Read the ‘Go further’ box with the class. Focus on what string manipulation is, and when you would use it in a chatbot to allow the input to be stored in one format. Demonstrate the code in the ‘Go further’ box using the file stringManipulationExamples.py to allow students to see the impact each example has on the program code. The pseudocode is from the ‘Iterations and arrays’ section in Lesson 6 for a chatbot that asks the user for colours. Students need access to the rainbowColoursChatbotV1.py file that they created in the same lesson. Encourage them to use pen and paper or to discuss how a user may enter the different colours. 3 Students need RainbowColoursChatbot.docx to annotate the pseudocode to incorporate string manipulation for the user’s input and to output the number of items in the array. Highlight that the output of the number of items in the array is after each input, so will be output during each iteration of the count-controlled loop. 4 Remind students that the aim is for all the inputs in the program to be changed to lowercase, and that after each input the number of items in the array is output too. This means that the additional line of code will be inside the for loop under the input line of code. Students should save the new iteration as rainbowColoursChatbotV2.py. 5–6 Students need to think about how to test the program iteration, e.g. if lower() is used, then the test would be to input all the colours in uppercase to see whether the input is changed to lowercase. Answers 1–2 A user may enter the colours in lowercase, e.g. ‘red’; in uppercase, e.g. ‘RED’; or with an initial uppercase, e.g. ‘Red’. 3 Here is an example of how it may look in pseudocode: START ARRAY rainbow = [red, orange] FOR i = 0 TO 4 Add INPUT to ARRAY "Add a colour" ENDFOR OUTPUT "--------------------" OUTPUT "Your rainbow colours are:" FOR each colour in ARRAY rainbow: OUTPUT colour ENDFOR STOP

Use string manipulation to change all inputs to lowercase. Add a new line of code to output the number of items in the array.Sample ©Hodder Education 53

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

4 For a solution, refer to rainbowColoursChatbotV2(Teacher).py. 5–6 Testing needs to include the way in which a user may enter the colours, e.g. ‘YELLOW’, ‘Yellow’ or ‘yellow’. Here is an example of possible test data is.

Test Test data Expected outcome Pass/fail

Normal YELLOW yellow Pass Normal Yellow yellow Pass Normal yellow yellow Pass Extreme YeLlOw yellow Pass Extreme YELlow yellow Pass Extreme yelLOW yellow Pass Challenge yourself (Student’s Book page 51) 1 Ask students to read individually or in pairs the text in the ‘Challenge yourself’ box. Explain that this is additional code that can be used to combine two arrays in an output. Students should save their program as challengeYourself.py. 2–3 Students need to use word-processing software to create a suitable test plan and consider whether they can include normal, extreme and invalid test data. Answers 1 For a solution, refer to challengeYourself(Teacher).py. 2–3 Test data would not go beyond normal in this instance as the input would take any words and output them. There could not be anything built into the program to detect whether a name is true or not.

Test Test data Expected outcome Pass/fail

Normal Joe, Sam, Tom Computing, Maths, Science

Joe likes Computing Sam likes Maths Tom likes Science Review l Provide students with stringManipulation.py and ask them to complete the code to match each instruction using uppercase, lowercase, initial uppercase and length string manipulation. l For a solution, refer to stringManipulation(Teacher).py. Homework Ask students to consider the use of string manipulation and to review the ‘Scenario’ at the start of the unit, ahead of the next lesson when they will start the ‘Final project’. Students should consider the scenario of a program for selecting their options or subject areas and think about how they could use an array for subject options, e.g. they could set up subject options in an array and use string manipulation for selecting the subject to ensure that it matches the way it has been stored in the array. Sample ©Hodder Education 54

9.1 Presenting choices: Combining constructs

Go further Stretch: Following task 4, students have the opportunity to create a further development iteration of their program by using capitalize instead of lower and observing the difference in output. Note that they should also edit the items in the array so that they begin with an uppercase letter. This may become obvious when they run their program to test it. Students should save their new developments as rainbowColoursChatbotV3.py. For a solution, refer to rainbowColoursChatbotV3(Teacher).py. Support: Students may benefit from some support in task 2 when they consider how a user may enter the colours. Ask students to choose a colour and write each letter on a separate sticky note in lower and uppercase. They can use the notes to spell out the colour with different combinations of upper- and lowercase letters. Differentiation Sample ©Hodder Education 55

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

UNIT 9.1 LESSON 10

Student’s Book pages 52–54

l Final project l Evaluation l What can you do?

Boost online resources

l 9.1 Knowledge test l finalProjectV1(Teacher).py*

l finalProjectStretch(Teacher).py* l 9.1 Keywords flashcards * These files contain completed examples and are provided for teacher reference to support evaluation of student responses to the tasks. Students need access to IDLE on their devices to complete the Python programming tasks. They also need access to word-processing software, e.g. MS Word, if they are completing the written tasks digitally.

Success criteria

Share the following success criteria at the start of the lesson:

Learning objective Success criteria for students

9CT.03 Know how to create algorithms using flowcharts and pseudocode. I can create algorithms using flowcharts and pseudocode. 9CT.06 Understand and use iteration statements, limited to count-controlled loops, presented as either flowcharts or pseudocode. I can explain and use iteration statements with count-controlled loops in either pseudocode or flowcharts. 9CT.09 Combine multiple constructs (sequence, selection, count-controlled iteration) to write algorithms as flowcharts or pseudocode. I can create an algorithm as a flowchart or pseudocode using more than one construct: sequence, selection and count-controlled iteration. 9P.01 Explain the purpose of a one-dimensional array. I can identify and explain the purpose of a onedimensional array. 9P.02 Identify and describe data types in text-based programs, including integer, real, character, string and Boolean. I can identify and describe data types in Python programs, including integer, real, character, string and Boolean. 9P.03 Know how to develop text-based programs with count-controlled loops. I can develop a Python program with countcontrolled loops. 9P.04 Know how to access data from an array using a text-based language. I can access data from an array using Python. 9P.05 Know how to develop text-based programs using string manipulation, including length, uppercase and lowercase. I can develop Python programs using string manipulation, including length, uppercase and lowercase. 9P.06 Use iterative development on software prototypes to produce solutions to problems. I can use iterative development on Python prototypes to create solutions to problems. 9P.07 Evaluate the processes that are followed to develop programs.

I can evaluate the processes that are followed to develop programs.Sample ©Hodder Education 56

9.1 Presenting choices: Combining constructs

Starter

l Focus students’ attention on the success criteria. Prompt students to take this opportunity to request a review of any content already covered before embarking on the ‘Final project’. l Ask students to reread the ‘Scenario’ at the start of the unit in the Student’s Book. Ensure that students understand the given criteria for the chatbot. l Students should complete the ‘Final project’ individually, but you can provide guidance on a oneto-one basis to those students who require it.

Activity notes and answers

Final project (Student’s Book page 52)

l The ‘Final project’ for this unit contains five parts (‘Plan’, ‘Develop the algorithm’, ‘Test the algorithm’, ‘Development’, ‘Evaluation of the prototype’). l Stress that students should consider debugging opportunities in each iteration to develop the program continuously throughout planning and creation stages. l In all tasks, remind students to save their work regularly and to include their name or initials in the files that they create. l Monitor students’ progress as they work through the tasks. For students who are struggling or for those who need more stretch, refer to the ‘Differentiation’ section below. l Provide students with the following list of the files they must submit when they have completed the ‘Final project’ tasks. –‘Plan’: Word-processed or handwritten, including a table listing the variables, data types and arrays. –‘Develop the algorithm’: Word-processed or handwritten pseudocode with annotations. –‘Test the algorithm’: Completed trace table; created test plan. – ‘Development’: FinalProjectV1.py. –‘Evaluation of the prototype’: Word-processed or handwritten paragraph.

Learning objective Success criteria for students

9P.08 Know how to develop and apply test plans that include normal, extreme and invalid data. I can develop and apply test plans that include normal, extreme and invalid data. 9P.09 Identify test data that covers normal, extreme and invalid data. I can identify test data that covers normal, extreme and invalid data. 9P.10 Identify a range of errors, including syntax, logic and runtime errors. I can identify and describe a range of errors, including syntax, logic and runtime errors. 9P.11 Use trace tables to systematically debug text-based programs.

I can use a trace table to check the flow of a variable through an algorithm and a Python prototype. Keywords Flashcards for the following keywords are available in the Boost online resources: l dry run l evaluation Sample ©Hodder Education 57

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Answers Part 1: Plan 1 Possible questions include: – What subjects do you enjoy? – What subjects are you good at? 2 Variables are individual but need to be suitably named, e.g. ‘option1’. Variable Data type Name String Integer choice1 Integer choice2 Integer Item Integer 3 Array name = subjects Array name = enjoy Array name = chosen Part 2: Develop the algorithm 1 Here is a possible solution is. 1 START 2 ARRAY subjects = "History" "Geography" "Music" "Drama" "Art" "Design and Technology" "Computer Science" "ICT" 3 ARRAY enjoy 4 ARRAY chosen 5 6 OUTPUT "Welcome to the subject choice chatbot" 7 name = INPUT capitalised "Please enter your name" 8 OUTPUT name "I am going to help you choose 3 subjects to continue studying" 9 OUTPUT "--------------------" 10 11 OUTPUT "First, I would like you to select 5 subjects from the following list:" 12 13 FOR i = 0 to length of ARRAY subjects 14 OUTPUT i+1, ARRAY subjects[i] 15 ENDFOR 16 17 FOR i = 0 to 4 i Sample ©Hodder Education 58

9.1 Presenting choices: Combining constructs

18 choice1 = INPUT "Enter the number of a subject you enjoy: " 19 IF choice1 >= 1 and choice1 <= length of ARRAY subjects THEN 20 append subjects[choice1 – 1] to ARRAY enjoy 21 ELSE 22 OUTPUT "That was not a valid choice" 23 ENDIF 24 ENDFOR 25 26 OUTPUT "--------------------" 27 28 OUTPUT "Now, I would like you to select the 3 subjects that you are best at" 29 OUTPUT "Here are the subjects that you enjoy:" 30 31 FOR i = 0 to length of ARRAY enjoy 32 OUTPUT i+1, ARRAY enjoy[i] 33 ENDFOR 34 35 FOR i = 0 to 2 36 choice2 = INPUT "Enter the number of a subject you are good at: " 37 IF choice2 >= 1 and choice2 <= length of ARRAY enjoy THEN 38 append enjoy[choice2 – 1] to ARRAY chosen 39 ELSE 40 OUTPUT "That was not a valid choice" 41 ENDIF 42 ENDFOR 43 44 OUTPUT "--------------------" 45 46 OUTPUT name "You should consider studying the following subjects next year:" 47 FOR item in chosen 48 OUTPUT item 49 ENDFOR 50 STOP Sample ©Hodder Education 59

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

2 The array ‘subjects’ stores the list of subjects to select from.

The arrays ‘enjoy’ and ‘chosen’ store the subjects the user selects.

The count-controlled loops output each item stored in the array, and allow the user to choose their options. 3 The data types used are integers for the subject choices and count variables and a string for the user’s name. Float/real numbers are not used as no decimal numbers are used in this program. A

Boolean data type is used as the output to the selection conditional statements. 4 String manipulation has been used in this program to give an initial uppercase letter to the user’s name when input.

Part 3: Test the algorithm

1 Trace table with inputs as choice1: 1, 3, 5, 8, 7 and choice2: 2, 5, 1:

Line Array Array Array VariableVariableVariable Condition Variable Condition Variable Output subjects enjoy chosen name i choice1 choice1 >= 1 and choice1 <= length of subjects choice2choice2 >= 1 and choice2 <= length of enjoy

item 2 History, Geography, Music, Drama, Art, Design and technology, Computer science, ICT 6 Welcome to this subject choice chatbot Eesa Please enter your name 8 Eesa I am going to help you choose 3 subjects to continue studying 9 ------------------11 First, I would like you to select 5 subjects from the following list: 14 0 1 History 14 1 2 Geography 14 2 3 Music 14 3 4 Drama 14 4 5 Art 14 5 6 Design and technology 7 Sample ©Hodder Education 60

9.1 Presenting choices: Combining constructs

Line Array Array Array VariableVariableVariable Condition Variable Condition Variable Output 14 7 Computer science 14 7 8 ICT 18 0 1 Enter the number of a subject you enjoy 19 TRUE 20 History 18 1 3 Enter the number of a subject you enjoy 19 TRUE 20 History, Music 18 2 5 Enter the number of a subject you enjoy 19 TRUE 20 History, Music, Art 18 3 8 Enter the number of a subject you enjoy 19 TRUE 20 History, Music, Art, ICT 18 4 7 Enter the number of a subject you enjoy 19 TRUE 20 History, Music, Art, ICT, Computer science 26 ------------------28 Now, I would like you to select the 3 subjects that you are best at 6 Sample ©Hodder Education 61

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Line Array Array Array VariableVariableVariable Condition Variable Condition Variable Output 29 Here are the subjects that you enjoy 32 0 1 History 32 2 Music 32 2 3 Art 32 3 4 ICT 32 4 5 Computer science 36 0 2 Enter the number of a subject you are good at 37 TRUE 38 Music 36 1 5 Enter the number of a subject you are good at 37 TRUE 38 Music, Computer science 36 2 1 Enter the number of a subject you are good at 37 TRUE 38 Music, Computer science, History 44 ------------------46 You should consider studying the following subjects next year: 48 0 Music 48 1 Computer science 48 2 History 1 Sample ©Hodder Education 62

9.1 Presenting choices: Combining constructs

2–3 Here is an example of possible normal, extreme and invalid test data; this could be expanded for more possible inputs and combinations of inputs from array options. Test Test data Expected outcome Pass/fail Normal eEsA Eesa I am going to help you choose 3 subjects to continue studying Normal Art (in list of subjects enjoyed) Extreme 1 History (in list of subjects chosen) Invalid 0 That was not a valid choice Part 4: Development 1–2 For a possible solution, refer to finalProjectV1(Teacher).py. 3 Students should use their program code to work through a copy of the trace table they created in Part 3. 4 Students can use the test plan they created in Part 3 to test that the program code works as expected. 5–6 Students need to save a new version of the program prototype, e.g. finalProjectV2.py, once they have identified and corrected any errors. Part 5: Evaluation of the prototype 1–3 Analyses should include that: – an iterative process allows the program to be created, tested and reviewed continuously to ensure that the program is fully functional and meets all requirements, before the final program is released for someone to use – a trace table allows the programmer to check the flow of an array, variable and conditional statement through a program to look for errors such as logical ones linked to comparison operators; this is a tool to help find and fix errors before the program is released to a user – a test plan looking at normal, extreme and invalid inputs allows a programmer to check that the program gives the outputs expected and can deal with unexpected inputs, e.g. using else to give a suitable message for an invalid input. Development iterations will differ based on each student’s own testing and reviews, e.g. they may find that they have not considered the output if the user enters an invalid input; this will lead to additional code being added, and the student should save the program code as a new iteration, with clear version control, i.e. V2, V3, etc. 4 A logical error occurs when the program runs but does not give the output expected. This could be linked with a comparison operator that has been used incorrectly. A syntax error is an error in the structure of the program code, and it generates an error as soon as the program is run. The error message can help to find and fix the problem. A runtime error occurs while the program is being run if, for example, a variable name has been spelled incorrectly. It produces a traceback message that helps to find and fix the error. 5 Sample ©Hodder Education 63

CAMBRIDGE LOWER SECONDARY COMPUTING 9 TEACHER'S GUIDE

Review Evaluation (Student’s Book page 53) 1 Allow appropriate time at the end of the ‘Final project’ for students to carry out the ‘Evaluation’ exercises. Remind students that part of evaluating a product is gathering feedback from users. Ask students to evaluate their programs in pairs using the questions provided in the Student’s Book and to make a list of recommendations. 2–3 Once students have read the peer feedback, allow them time to make additional changes before submitting their ‘Final project’. What can you do? (Student’s Book page 54) l Students should review in pairs the contents of the ‘What can you do?’ box at the end of the unit. If students are not confident in any of the learning outcomes, spend time on areas of misunderstanding before progressing to the next unit of study. l Ask students to complete the 9.1 Knowledge test. Use this test to assess their understanding of data types, types of tests, Python programming, arrays, count-controlled iteration and string manipulation. Remind students to read the questions carefully to ensure that their answers are correct, and to read the program-code examples fully to select the correct answer. Homework l Students could complete tasks 2–3 of the ‘Evaluation’ box if they were unable to finish them during lesson time. l Students could also finish the 9.1 Knowledge test if they didn’t complete it in the Review stage of the lesson. Final project Stretch: To make Part 4 more challenging, students should consider how the chatbot would show that it has finished, to make it act more like a human interaction, e.g. would the chatbot check that the user is happy and ready to end the session or offer further steps if a decision has not been reached? Remind students to test any updates and save these as a new iteration of the program. For a solution, refer to finalProjectStretch(Teacher).py. Support: Some students may need support in Part 5 to understand how to evaluate a process that they have been told needs to be completed. Ask students ‘what’, ‘when’, ‘how’ and ‘why’ questions, linked to each process, e.g.: l What is the process? (A trace table is created to track the content of a variable or array through conditional statements and outputs.) l When do you complete it? (It can be completed on an algorithm and on the program code.) l How is it completed? (A structured table is created to allow the line number and the code to be tracked throughout.) l Why is it completed? (To locate errors.) Differentiation Sample ©Hodder Education 64

This article is from: