Digital Production, Design and Development T Level Core PDF
Document Details
Uploaded by UnmatchedScholarship1318
Mo Everett, Sonia Stuart
Tags
Summary
This textbook is about Digital Production, Design and Development T Level. It covers problem solving, programming, emerging digital issues, legislation, business contexts, data and digital environments, security and assessment.
Full Transcript
This page intentionally left blank 346789_FM_DD_TLevel_Core_i-iv.indd Page 1 04/08/22 12:45 PM F-0250 /101/HO02419/work/indd DIGITAL PRODUCTION, DESIGN & DEVELOPMENT CORE...
This page intentionally left blank 346789_FM_DD_TLevel_Core_i-iv.indd Page 1 04/08/22 12:45 PM F-0250 /101/HO02419/work/indd DIGITAL PRODUCTION, DESIGN & DEVELOPMENT CORE Mo Everett Sonia Stuart 346789_FM_DD_TLevel_Core_i-iv.indd Page 2 14/01/23 7:51 AM A4902 /Data%20Disk/Manoj%20R/Dec/24-12-22/HO02737_142 Although every effort has been made to ensure that website addresses are correct at time of going to press, Hodder Education cannot be held responsible for the content of any website mentioned in this book. It is sometimes possible to find a relocated web page by typing in the address of the home page for a website in the URL window of your browser. Hachette UK’s policy is to use papers that are natural, renewable and recyclable products and made from wood grown in well-managed forests and other controlled sources. The logging and manufacturing processes are expected to conform to the environmental regulations of the country of origin. Orders: please contact Hachette UK Distribution, Hely Hutchinson Centre, Milton Road, Didcot, Oxfordshire, OX11 7HH. Telephone: +44 (0)1235 827827. Email [email protected] Lines are open from 9 a.m. to 5 p.m., Monday to Friday. You can also order through our website: www.hoddereducation.co.uk ISBN: 978 1 3983 4678 9 © Maureen Everett and Sonia Stuart 2023 First published in 2023 by Hodder Education, An Hachette UK Company Carmelite House 50 Victoria Embankment London EC4Y 0DZ www.hoddereducation.co.uk Impression number 10 9 8 7 6 5 4 3 2 1 Year 2027 2026 2025 2024 2023 All rights reserved. Apart from any use permitted under UK copyright law, no part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying and recording, or held within any information storage and retrieval system, without permission in writing from the publisher or under licence from the Copyright Licensing Agency Limited. Further details of such licences (for reprographic reproduction) may be obtained from the Copyright Licensing Agency Limited, www.cla.co.uk Cover photo © Seventyfour – stock.adobe.com Typeset in India Printed in Bosnia & Herzegovina A catalogue record for this title is available from the British Library. 346789_FM_DD_TLevel_Core_i-iv.indd Page 3 05/09/22 4:29 PM user /101/HO02419/work/indd Contents Contents Guide to the book...................................................................................................... iv Content area 1 Problem solving.....................................................................................................................................1 Content area 2 Introduction to programming............................................................................................................14 Content area 3 Emerging issues and impact of digital..............................................................................................55 Content area 4 Legislation and regulatory requirements.........................................................................................69 Content area 5 Business context................................................................................................................................100 Content area 6 Data....................................................................................................................................................135 Content area 7 Digital environments........................................................................................................................164 Content area 8 Security..............................................................................................................................................208 Assessment........................................................................................................................................232 References............................................................................................................... 241 Glossary................................................................................................................... 242 Acknowledgements...............................................................................................247 Index......................................................................................................................... 248 iii 346789_FM_DD_TLevel_Core_i-iv.indd Page 4 04/08/22 12:45 PM F-0250 /101/HO02419/work/indd Digital Production, Design and Development T Level: Core Guide to the book Learning outcomes Research Summaries of the knowledge outcomes that you Research-based activities – either stretch-and- need to learn in each content area. challenge activities, enabling you to go beyond the course, or industry placement-based activities encouraging you to discover more about your placement. Key term Definitions of key terms. Case study Scenarios that place content into real-world Industry tip contexts. Tips and advice to help you in the workplace. Test yourself Important point Short questions designed to test your knowledge and understanding. Important points that you need to be aware of. Assessment practice Activity Knowledge-based practice questions to help you Short activities that encourage you to apply the to prepare for the core exams. knowledge and skills covered in the Student Book. Skills practice Short scenarios and focused activities that allow you to apply the skills you have learned in each content area. iv 346789_C01_DD_TLevel_Core_001-013.indd Page 1 04/08/22 12:44 PM F-0250 /101/HO02419/work/indd Content area 1: Problem solving Problem-solving skills can be used to analyse exploring the advantages and disadvantages of problems. This will lead to solutions which can then be each method. You will also learn about the different developed into code for digital systems. Computational representations of each algorithmic method and how thinking, which you are going to explore in this content to use them to create an algorithm that accurately area, provides a framework for the ways in which a represents a problem. problem can be solved. It is very important that algorithms are correct, solve You will also learn about the different approaches the problem and produce the correct, and expected, that can be applied to problem solving and how these output. You will learn how a visual check and trace can lead to the creation of algorithms to define the tables can be used to ensure that the created processes. There are different methods of creating algorithm is fit for purpose, providing a clear and algorithms including flowcharts, written descriptions, robust design to inform the coding of the solution to pseudocode and program code. You will learn how the problem. they can be used to create algorithms, as well as Learning outcomes In this content area you will learn about: 1.1 Computational thinking 1.2 Algorithms 1 346789_C01_DD_TLevel_Core_001-013.indd Page 2 16/01/23 2:33 PM A4902 /Data%20Disk/Manoj%20R/Dec/24-12-22/HO02737_142 Digital Production, Design and Development T Level: Core abstraction. Using the top-down approach, it is 1.1 Computational thinking possible to break a problem into detailed sub- By applying computational thinking to an problems. The top-down approach begins with overarching problem, you can understand what the abstract problem and refines the problem by the problem is, and what it consists of, to help you decomposition until no more decomposition can be develop a possible solution. The solutions to the carried out. problem can be shown in ways that a digital system, a person, or both, can understand. Key terms Computational thinking: a problem-solving method 1.1.1 Using top-down, bottom-up and using computer science techniques, where possible modularisation approaches to solve solutions are developed and presented in a way that problems can be understood by humans and computers. Decomposition: breaking a complex problem into When solving problems related to the use of digital smaller sub-problems. systems there are three main approaches that can be taken: Abstraction: the process of removing or filtering characteristics that are not needed, in order to focus top-down on essential characteristics. bottom-up modularisation. Top-down approach Bottom-up approach The bottom-up approach is the opposite of the top- The top-down approach is a technique used to solve down approach (Figure 1.1). The process starts with the problems where the problem is broken down into smallest part, module, of the problem. These are then smaller and smaller problems, modules, until an easily combined to move up a level and this then carries on solved problem is defined. until the complete problem is solved. The combination This means that the top-down approach divides of the modules is called integration. a complex problem into multiple smaller parts Table 1.1 shows the main differences between the top- which can then be used to code the associated down and bottom-up approaches. modules. Each module is decomposed until the final module(s) cannot be further decomposed. This Top-down Bottom-up approach uses a stepwise process to break a large Concept Splitting Merging problem into simpler and smaller problems, modules, to organise and code the software program in an (Breaks the (Solves the effective and efficient way. The flow of control in this massive problem fundamental low- into smaller sub- level problems and approach is always in the downward direction. problems) integrates them into The top-down approach is usually represented as a tree a larger one) structure as shown in Figure 1.1. Redundancy Contains redundant Redundancy can be information eliminated Programming Structure/ Object-oriented languages procedural-oriented programming programming languages (e.g. languages (e.g. C) Python, Java) Main use Module Testing ▲ Figure 1.1 A top-down approach (left) and a documentation, test bottom-up approach (right) case creation, code implementation and Each level in the top-down approach shows a debugging different level of detail (abstraction) with the ▲ Table 1.1 Features of top-down and bottom-up top level, level 1, showing the greatest level of approaches to problem solving 2 346789_C01_DD_TLevel_Core_001-013.indd Page 3 04/08/22 12:44 PM F-0250 /101/HO02419/work/indd Content area 1: Problem solving Modularisation approach Decomposition Abstraction The modularisation approach aims to break a problem into different components, or modules. Most problems are not one big problem but are a collection of different Pattern recognition Algorithms tasks, modules, which are independent and can be separated. A big problem can seem daunting but by breaking it into smaller tasks, modules, the problem can become more manageable and solvable. All these modules work together to provide a solution to the initial problem. A module can be seen as a subprogram where the main program ‘calls’ each module. This is a strategy often utilised in object- ▲ Figure 1.2 The four techniques, or pillars, of oriented programming languages. computational thinking Decomposing a problem is the technique of breaking Activity a complex problem or system into smaller, more Split into three groups. Each group should choose manageable separate parts. These can also be called a different problem-solving approach: top-down, modules when the solution is being created. bottom-up or modularisation. Once the problem has been broken down, its separate You want to make a cooked dessert as a treat for parts can be understood independently. This also your family. Using your group’s chosen approach, means that the parts can then be developed separately produce a document showing the steps that should to solve the initial problem. Each part can also be be taken. evaluated, or tested, when a program has been Each group should then present their solutions. developed. Using decomposition makes complex problems easier to solve, and large digital systems easier to design and create. Test yourself Solving a complex problem as a whole may seem very difficult. However, the solution to each decomposed 1 What is computational thinking? part may be much simpler. When all the parts are 2 How is the top-down approach usually solved, these solutions can be put together. This will represented? provide a solution to the initial problem. 3 What does the top-down approach begin with? 4 What type of programming languages use the Decomposing problems is a skill that is needed in many bottom-up approach? different job roles including project management and 5 What is the combination of modules called? software design. When a project is being planned, the 6 What is the aim of the modularisation approach? initial project is broken down into many different subtasks which have to be completed to complete the project. 1.1.2 Decomposing problems Activity There are four techniques, also known as pillars, that You have been asked to plan a trip to Bletchley Park can be utilised as part of computational thinking. for your teaching group. Split into smaller groups of three or four. Plan the trip and create a digital These are: communication to show all the tasks and subtasks decomposition which would be needed. Each group should present pattern recognition their plan. abstraction Was everything included to make the trip a success? algorithms. Identify any tasks or subtasks that were forgotten, Decomposition is one of the techniques involved in considering the impact these omissions would have on the trip. the process of computational thinking. 3 346789_C01_DD_TLevel_Core_001-013.indd Page 4 04/08/22 12:44 PM F-0250 /101/HO02419/work/indd Digital Production, Design and Development T Level: Core The top-down approach to problem solving uses 4 Communicate – most software solutions are coded decomposition. This is because the initial problem by a team of people. When a problem has been is broken down until no more decomposition can be decomposed it is possible that each person will take carried out. When decomposition is complete, each sub- responsibility for coding a specified task or sub- problem should be at the same level of detail and able to tasks – also known as modules. When the modules be solved on its own. Once coded, the modules are then have been coded then they can be bolted together combined to solve the initial problem. to provide a solution to the given problem. The top-down approach was covered in section 1.1.1 of You will learn about the different sectors of business this content area. in Content area 5, section 5.1.1. Advantages and disadvantages of Test yourself decomposition The advantages of using decomposition to analyse, 1 What is decomposition? plan and create a digital solution include that: 2 What are modules? Different people can work on the different sub- 3 How does the top-down approach use tasks, modules, which can then be integrated to decomposition? make the final solution. 4 Identify one advantage and one disadvantage of Maintenance of the final software solution can be decomposition. completed at modular level. The disadvantages of using decomposition to analyse, 1.1.3 Using pattern recognition plan and create a digital solution include that: When a problem has been decomposed into the smallest The sub-problem modules may not combine to sub-problems, it is often possible to identify patterns. solve the initial problem. Patterns can be found everywhere. For example, every If the initial problem is not fully understood, then it school and college has a timetable showing lessons, can be difficult to decompose. teachers, rooms, days and times. This is an example The four steps of decomposition of a pattern. This is because the timetable runs for an academic year and does not change over the year. When decomposing a problem ready for coding there are four steps that should be carried out: Research 1 Identify and describe the problems and processes – the problems should be identified To understand pattern recognition, it is best to start and described. It is important that at this stage by thinking about things in a non-digital context. the technical terms used should match the sector Investigate the artist M.C. Escher. How does the the problem relates to. For example, if the problem artist use patterns in their work? relates to the retail sector then terms related to the retail sector should be used. The identification and recognition of patterns – things 2 Break down the problems into separate tasks – that are common between problems or programs – is this stage begins to decompose the problem. It is one of the pillars of computational thinking. Patterns usual to use the top-down approach as the problem is can help to solve complex problems more efficiently. known. There is no limit on the number of tasks and There are patterns that are used in many situations. For subtasks that can be identified. What is important example, Morse Code was used during World War 2 is that the problem is decomposed until it can be and for communication between ships. decomposed no further. It is also important that the final decomposition should only include tasks and Research subtasks that fully relate to the initial problem. 3 Describe the tasks and subtasks – this stage Binary uses a pattern of 1s and 0s to represent requires documentation to be created that relates to each letter of the alphabet. Find the patterns that the decomposition. The documentation produced are used in binary to represent each letter. Write should be clear and concise to enable a third party a phrase in binary. Share your phrase with your to implement the solution to the problem. group and ask them to decipher it. 4 346789_C01_DD_TLevel_Core_001-013.indd Page 5 04/08/22 12:44 PM F-0250 /101/HO02419/work/indd Content area 1: Problem solving Continuing work done by Polish code breakers shared 2 Identifying and interpreting common with the UK, the code breakers at Bletchley Park, differences in problems or systems – using the including Alan Turing, deciphered the coded messages customer database example, all customer databases which had been ciphered by the Enigma Machine. The store records of customers. What information is Enigma Machine used different ciphers to convert each held about the customers and how the information message into code. Each cipher had a pattern and it is recorded may be different, but the purpose of the was the recognition of these patterns that provided the databases is the same – to store information. initial breakthrough when identifying the cipher used 3 Identifying individual elements in the for each message. patterns – the elements can be input, process or output. For example, the customer database may Research record the number of times a customer has placed an order. These orders may be recorded as a number Research the Enigma Machine and how the cipher or by recording the date each order was placed. The was cracked by Alan Turing and the team at inputs are different but the process of calculating Bletchley Park. Create a digital communication to the number of times is the same. present the results of your research. 4 Describing patterns that have been identified – when a pattern has been identified, then it needs to Pattern recognition can also be used in a range of be described. The pattern may be new or one that emerging technology applications. For example, facial occurs several times. recognition, voice recognition software and automated 5 Making predictions based on identified transport. These applications use predefined and patterns – when a pattern has been identified then pre-learned patterns to process the inputs and produce a decision can be made about using it multiple outputs. times in code or reusing it in a different program. Key term When the patterns have been identified, it is usually only the specific details that need to be changed within Facial recognition software: software that can any module of code. identify or confirm someone’s identity using their face in a photo, video or in real time. Test yourself 1 What is pattern recognition? Research 2 What would be the result of not identifying Select an emerging technology application. patterns when starting to code? Investigate how the application uses patterns and 3 How do emerging technology applications use its advantages and disadvantages. Discuss your pattern recognition? findings with the rest of your teaching group. 4 Identify and describe one step used in identifying and recognising patterns. By identifying and recognising patterns, it is possible when coding to locate a pre-existing module of code. 1.1.4 Using abstraction There are five main steps to identifying and recognising patterns when beginning to code. Identifying necessary information and 1 Identifying and interpreting common elements filtering out the unnecessary in problems or systems – when a common pattern Abstraction is the process of removing or filtering has been identified, there is more than likely going characteristics that are not needed, in order to focus on to be an existing solution to the problem. For essential characteristics. example, a search can be carried out for a specific customer in a customer database. The process of A well-known example of abstraction is the London searching a database varies slightly depending on Underground map. the type of database, the number of records or the purpose of the database. 5 346789_C01_DD_TLevel_Core_001-013.indd Page 6 04/08/22 12:44 PM F-0250 /101/HO02419/work/indd Digital Production, Design and Development T Level: Core Research Produce a table showing specific and general details for driving a car. Compare your results with the rest of your teaching group. Creating layers of abstraction Each layer of abstraction hides the complexity of the layer below. This means that the top abstraction layer hides all the complexity of the problem. There are two main steps involved in abstraction. 1 The information needed to solve a given problem needs to be identified as, without this, the solution may not solve the problem. It is also important ▲ Figure 1.3 The London Underground map is an to know and understand why this information is iconic visual representation used by millions of needed. The required format of the information people to plan their journeys should also be considered. 2 Carry out abstraction to filter out the unrequired By looking at the map, it is possible to plan a journey, information. This means that only the information know how many stations will be visited and if required will be considered. Anything else will be changes of line need to be made and where. It is not a distraction to the process. It is also important to necessary to know how many miles the journey will know and understand why information is required take or where each station is in relation to the next – and not required. these have been filtered out of the map during the process of abstraction. Each layer of abstraction needs to be complete. This means that each layer should show: By carrying out abstraction it enables a general idea the inputs – what is inputted into the digital system of what a problem is and how it can be solved. The at that level. This could include validation, and the process removes specific detail and patterns that do format of the input, for example currency shown to not help you to solve the problem. If abstraction is not two decimal places carried out, then it is possible that an incorrect solution the outputs – how and in what format the output to the problem may be provided. will be given. For example, a printed document Abstraction provides a general idea of the problem showing specified data and information or on- rather than focusing on specific details. This general screen output. This is usually specified by the client idea is known as a model. By carrying out abstraction variables – these are values that will change. the complexity can be reduced while the efficiency can Variables usually change as a result of an input by be increased. an end user or of a calculation being carried out constants – these are values that do not change. A Table 1.2 shows the difference between specific constant could be, for example, a fixed delivery price and general detail, using the example of making a key processes – these are the actions, processes, casserole. that the layer must carry out General Specific repeated processes – these are processes that are carried out several times in a digital system. A casserole needs It is not required to know ingredients. what ingredients. Key terms Each ingredient has a It is not required to know required quantity. the quantity of each Variables: in the context of abstraction, these are ingredient. values that will change usually as a result of an input A casserole needs to be It is not required to know or of a calculation being carried out. cooked for a long time. the cooking time. Constants: values in a program that do not change ▲ Table 1.2 General versus specific when the program is being executed or run. 6 346789_C01_DD_TLevel_Core_001-013.indd Page 7 04/08/22 12:44 PM F-0250 /101/HO02419/work/indd Content area 1: Problem solving Algorithms are the basis on which all software is Activity created. An algorithm is language independent. This means that step-by-step instructions can Create the lowest abstraction level for a digital system that can be used to calculate the costs of be implemented with the expected output being a school prom, including inputs, outputs, variables the same irrespective of which language is used. and constants. The output of the system should be An algorithm must: the cost of a ticket to the prom and how much profit be clear with clearly defined steps would be made. have clearly defined inputs and outputs be simple, generic and practical Test yourself be language independent. The advantages of algorithms include: 1 Why is abstraction important? They are easy to understand by anyone. 2 What is the aim of abstraction? They are a step-by-step representation of a solution 3 What happens to the efficiency when abstraction to a given problem. is carried out? The initial problem is broken down into steps, 4 Identify one step carried out in the process of abstraction. which means it is easier to convert into code. 5 What is a variable? The disadvantages of algorithms include: Creating a complete algorithm can be time consuming. 1.2 Algorithms Some constructs can be difficult to represent. You are going to explore the different approaches An algorithm can be represented as a flowchart, that can be applied to problem solving and how written description, pseudocode or program code. You these can lead to the creation of algorithms to define are going to explore each of these. the processes. There are different methods that can be taken to create algorithms. You will learn about Flowcharts how flowcharts, written descriptions, pseudocode A flowchart is a graphical diagram that represents an and program code can be used to create algorithms, algorithm which can be used to solve a problem. including the advantages and disadvantages of each. The advantages of flowcharts include: Each algorithmic method has defined representation. The flow of the program can be seen clearly. There are, for example, a set of symbols that are used Flowcharts are created using a standardised set of when creating a flowchart. You will learn about the symbols so can be interpreted and understood by different representations that are used and how to use many people. these to create an algorithm that accurately represents a solution to a problem. The disadvantages of flowcharts include: With a large, complicated program the flowchart It is very important that algorithms are correct, solve the can become very large and difficult to follow. problem and produce the correct, and expected, output. Changes to the design may result in the flowchart You will learn how a visual check and trace tables can being amended or redrawn. be used to ensure that the created algorithm is fit for purpose and, when combined with the other pillars of Written descriptions computational thinking, provides clear and robust design to inform the coding of the solution to the problem. Written descriptions are generally written in a natural language or plain English language. Unlike flowcharts, 1.2.1 What algorithms are and how pseudocode and program code, there is no defined they are expressed format for this method of algorithmic representation. A written description should be easy to understand and 1.2.4 The purpose of a given contain little, if any, specific detail. It is often better to algorithm and how it works use very short sentences. It is important, however, that all parts of the final decomposition of the problem are An algorithm is defined as a plan, or a well-defined included. set of step-by-step instructions, to solve a problem. 7 346789_C01_DD_TLevel_Core_001-013.indd Page 8 04/08/22 12:44 PM F-0250 /101/HO02419/work/indd Digital Production, Design and Development T Level: Core The advantages of using a written description include: Program code There is no formal syntax, so many people can Program code is usually considered to be the create a written description. code written to solve the problem which follows It is automatic and natural to use ‘proper’ English. the rules of the selected programming language. The disadvantages of using a written description include: However, program code can also be used to create the temptation to create a complete description an algorithm. In this situation the code is known as failure to include every step required. ‘draft program code’. Errors can be evident in the draft code as this will not Key term be used to run the final programming code. What is important is that, as with other algorithmic techniques, Syntax: in the context of algorithms, these are the structure of statements. the meaning is clear and it can be followed. The advantages of using programming code include: Pseudocode It is very probable that the person creating the Pseudocode is an informal programming description algorithm will have some programming knowledge. showing the flow through the process. Pseudocode is It is not necessary to use the correct syntax. written in a format that is similar to the structure of a All the required constructs will be available to be high-level programming language. Pseudocode provides included in the draft code. an outline of what the resulting program should achieve. The disadvantages of using programming code include: Pseudocode has its own syntax, some of which is It is easy to begin creating draft code but end up very similar to many actual programming languages. creating the final program code. Pseudocode algorithms will not run unless they are Full decomposition may not be completed. converted into an actual programming language. Research The advantages of using pseudocode include: The pseudocode can be converted into Find one more advantage and disadvantage for programming code with minor changes to obey the each of the algorithmic representations. Discuss syntax rules of the programming language. your findings with the rest of your teaching group. It can be easy to follow and understand even if errors are present in the pseudocode. Each algorithm will have a purpose which will be Unlike using a flowchart, changes can be the problem to be solved. There are a number of implemented quickly. methods that can be used to ascertain the purpose of It can act as a link between the algorithm and the an algorithm. If the algorithm is simple, then it can be final program. straightforward to determine the purpose. But if the It explains the purpose of each line of code, algorithm is more complicated, then a trace table can so if the pseudocode is fully complete and be used. A trace table is a tool that can be used to dry detailed, the creation of the final code should be run the algorithm. uneventful and meet the needs of the client. Dry running an algorithm means to use values for the The disadvantages of using pseudocode include: variables used in an algorithm and to trace, or run, the It can be as time consuming to write clear and processing before beginning to code. well-structured pseudocode as it is to write the final programming code. A trace table can allow the values assigned to the It can be difficult to see the logical flow of the program. variables to be recorded. Industry tip Key term There are many different variants of pseudocode. Trace table: a tool used to test or dry run algorithms Each organisation may use a different variant. The to make sure no logical errors occur while pseudocode you should use during this course calculations are being processed. Each column is defined in Appendix 2 of the qualification represents a variable and the rows represent the specification. numerical input and the output of the variable. 8 346789_C01_DD_TLevel_Core_001-013.indd Page 9 04/08/22 12:44 PM F-0250 /101/HO02419/work/indd Content area 1: Problem solving The simple pseudocode algorithm shows the Standard searching algorithms include linear and multiplication of a user input up to its 7th value. NUM binary searches, while standard sorting algorithms represents the user input to be multiplied up to the 7th include bubble and merge sorts. value. Searching and sorting methods are covered in The user inputs a value of 8 for NUM. The trace Content area 2, section 2.4.6. table shows the values that would be output by the algorithm. Many programming languages have libraries of pre-written and defined code that can be used. This RECEIVE num FROM (INTEGER) means that algorithms can use standard elements KEYBOARD from the libraries. There are advantages of using code from a library. One FOR number FROM 1 TO 7 DO is that it saves development time when creating the code. This will also save testing time as the pre-written SEND num * number TO DISPLAY END FOR code will have been used and tested by many different OUTPUT people. Another advantage is that the pre-written code will be optimised, meaning that the code will be num * number efficient and free of any errors. The main disadvantage of using code from a library is END FOR that it may not be exactly what is required. This will mean that the code will need to be edited, so taking NUM number Output more time. It may be quicker, in this case, to write the 8 1 8 code from scratch. By doing this, it can be guaranteed 2 16 that the code will meet the exact requirements. 3 24 It is sometimes difficult to integrate pre-written code into other code. You may need to edit to ensure that, 4 32 for example, any variable names or the data types used 5 40 are consistent. 6 48 More on using pre-written code in Content area 2, 7 56 section 2.5.1. By using a trace table, it can be confirmed that the logic and processing in the algorithm is correct. Research Many software programs have elements which Find standard pseudocode algorithms for a bubble perform the same task. This means that some sort and a linear search. Compare your results with algorithms follow patterns that can be recognised. the algorithms found by the rest of your teaching These are usually referred to as standard algorithms. group. What are the similarities and differences? These types of algorithms follow a set pattern and are usually connected with searching and sorting data. A visual check can also be used to determine the purpose of the algorithm. Looking at the simple Key terms pseudocode algorithm it is clear that this solves a maths problem, and that multiplication is involved. Search: examine data to find a specified value. This is shown by the use of the * operator and the Sort: put a data set into a specified order. loop that shows how many numbers should be output before the code stops. 9 346789_C01_DD_TLevel_Core_001-013.indd Page 10 14/01/23 7:55 AM A4902 /Data%20Disk/Manoj%20R/Dec/24-12-22/HO02737_142 Digital Production, Design and Development T Level: Core Data types are covered in Content area 6, Activity section 6.2.1. Using the pseudocode for the bubble sort and linear Symbol Meaning search you found, carry out a visual check. For each The start and end of the flowchart pseudocode create a written description algorithm. Could the pseudocode be made more efficient? A process that has to be carried out Test yourself A sub-process 1 What is an algorithm? 2 Identify one advantage and one disadvantage of using an algorithm. 3 Identify two ways algorithms can be represented. A decision – this must have 2 outputs: true/false, yes/no 4 What is meant by the term ‘language independent’? 5 What is meant by the phrase ‘completing a dry run’? An input or output 6 How can a trace table be used to check the logic and processing of an algorithm? A connection – used to link parts of a flowchart that cannot be easily 1.2.2 Express an algorithm using connected, for example when the flowchart goes onto a different page flowcharts and pseudocode, and understand how to use these when The flow of the algorithm – arrows are used to show the direction of planning a digital solution the flow 1.2.5 Determine the correct output of ▲ Table 1.3 Symbols used in flowcharts and their meanings an algorithm Activity 1.2.6 Identify and correct errors in an algorithm Create a flowchart to add six numbers together and output the average. A flowchart makes use of a standardised set of symbols which are connected by lines showing the flow of the algorithm. Flowcharts are used to visually show the Pseudocode includes a range of arithmetic expressions steps in a process. They should be simple and free from and relational and logical operators. any difficult to understand terminology or technical Arithmetic expressions are used in calculations. There jargon. are four standard expressions: There are many sets of flowchart symbols but the set add to be used in this course are shown in Table 1.3. divide multiply Pseudocode can use many different sets of syntax. In subtract. this course the syntax you will use is provided in the qualification specification in Appendix 2. However, the group also includes: exponent The syntax provided shows, for example, data types, modulo constants, data structures, identifiers and comments. integer division. Comments can be used to explain the process shown in the pseudocode. 10 346789_C01_DD_TLevel_Core_001-013.indd Page 11 04/08/22 12:44 PM F-0250 /101/HO02419/work/indd Content area 1: Problem solving Definition Example expression Activity Exponent A quantity representing 3^3 A retailer is having a sale. You will create a flowchart the power to which and pseudocode to meet their requirements. 3*3*3 = 27 a given number or expression is to be raised. Items are discounted based on the original selling This is represented by a ^ price. The table shows the original price and the Modulo/ The remainder after 50 % 8 = 6 discount. Modulus dividing one number remainder 2 by another. This is Lowest selling Highest selling Discount % 15 MOD 8 equals 2 price £ price £ represented by mod. Integer Division in which the 50 / 8 = 6 1.00 4.99 5 division remainder is discarded. remainder 2 5.00 9.99 10 This is represented by a / 50 DIV 8 = 6 10.00 19.99 15 ▲ Table 1.4 More pseudocode expressions and their 20.00 200.00 20 meanings Dry run your pseudocode, using a trace table to check the logic. Correct any errors that are found Activity and dry run the pseudocode again. Create pseudocode that calculates the modulo for 50 using numbers 1–10. Activity Relational operators are also used in pseudocode. They define a relationship between two values. There are six Create a flowchart to validate a password. The relational operators that are used in this course. password should be ten or more characters, and These operators can be used for numerical or text- include at least one number. If the password based data. does not meet these requirements, then an error message should be displayed, and the user asked to Description Example expression edit the password. = Equal to or equivalent x=9 When you have completed your flowchart pass it to Does not equal x 9 another person in your teaching group to carry out a dry run using test passwords that do and do not > Greater than x>9 meet the requirements. >= Greater than OR equals x >= 9 < Less than x= y True Less than xy right, the condition is true Greater than >= If the value on the left is greater than, or equal to, the value x >= y OR equals on the right, the condition is true Less than < If the value on the left is less than the value on the right, x 15 and 1 What is the Python notation for integer division be true if both x < 30 (DIV)? conditions are true 2 What is the purpose of the Modulus (MOD) NOT not The output of the not(x>15 and mathematical operator? condition will be x 15 and True Both of the conditions are true x < 30 not not (x>15 False Both conditions are true, but False is returned as the not operator reverses and x 35 or False Neither of the conditions are true x < 12 ▲ Table 2.8 The results of each Boolean operator 21 346789_C02_DD_TLevel_Core_014-054.indd Page 22 04/08/22 6:40 PM F-0250 /101/HO02419/work/indd Digital Production, Design and Development T Level: Core 2.3 File handling Mode (method) Python notation Explanation (parameter) Append “a” Opens a file for editing – 2.3.1 Text files for input and output appending of data The file is created if it does not exist Every programming language supports file handling. This means that when a program is being executed or Create “x” Creates the specified file run, files can be: An error is returned if the created file already exists opened Read “r” Python’s default value read A file is opened for reading written to/edited/appended An error is returned if the deleted. file does not exist Python has functions that can be used when file Write “w” Opens a file for writing handling is being carried out. Python treats files as text The file is created if it does or binary (e.g. images) depending on the contents of the not already exist file. Python defaults to text files. The Python notation ▲ Table 2.10 The four different modes (methods) of for declaring the type of file is given in Table 2.9. opening files in Python File type Python notation Explanation Opening and reading a file Text “t” Python’s default file type To open and read a file the name of the file should be Text mode given. In the example Python code the file name has Binary “b” Binary mode been given: Example – images h = open("practicefile.txt", "rt") ▲ Table 2.9 Python notation for declaring the type As Python defaults to reading a file and a text type file of file there is no need to define, in the code, that the file is to be read, “r” or the file type, “t”. This means that the Built-in functions are covered in section 2.5 of this code shown will be acceptable to Python to open and content area. read the text file ‘practicefile’. h = open("practicefile.txt") To open a file in Python the code is: open() If the file to be read is stored in the Python folder then the code to read and print the file would be: The function has two parameters which must be h = open("practicefile.txt", "r") declared. These are the file name and mode. print(h.read()) Key terms The inclusion of the “r” in the code is optional as Parameter: a special kind of variable in computer Python defaults to read. programming languages that is used to pass If the file is stored in a different location, then the code information between functions or procedures. to read and print the file would be: Append: adding additional data to an existing file. h = open("D:\\myfiles\practicefile. txt", "r") There are four different modes (methods) of opening files in Python. These are given in Table 2.10. print(h.read()) 22 346789_C02_DD_TLevel_Core_014-054.indd Page 23 04/08/22 6:40 PM F-0250 /101/HO02419/work/indd Content area 2: Introduction to programming It is also possible to loop through the file so that the file Activity can be read line by line. This code would be written as: Create and save a text file using the text: h = open("practicefile.txt", "r") This is my practice file. for x in h: The file is for practice. I hope it works! print(x) Save the file as practicefile.txt in the same location as Python and in a different location. This means that the output from this would be: Write Python code to read the file from the same This is my practice file. location as Python and from a different location. The file is for practice. The read function in Python, by default, will read I hope it works! the whole file. It is possible to read a specified number of characters in the file or a specified Closing a file number of lines. It is good practice to close files when actions have been completed. For example, the code shows the closing of the To read a specified number of characters in a text file practice file when the first 7 characters have been read. the function read() h = open("practicefile.txt", "r" ) print(h.read(7)) can be used. For example: h = open("practicefile.txt", "r") h.close() print(h.read(7)) When data has been written to, or edited/appended, it is important that the file is saved and closed. If this does will read the first 7 characters in your practice file. This not happen then any changes made to the contents of means that the output will be: the file will be lost and the file will not be up to date. This is Creating a new file To read a specified number of lines in a text file the New files need to be created. For example, a new business function will need to create a stock file. Python defaults to “r” which readline() will return an error message if the file does not exist. Each of the modes of opening files in Python will check if a file already exists or not; this is shown in Table 2.10. can be used. How many times this function is used in the code will be dependent on the number of lines that The modes append and write will create a new file if it need to be read. For example: does not already exist. But, the create mode will return h = open("practicefile.txt", "r") an error if the file does exist. To create a new file the open() notation is used. The mode print(h.readline()) required is then denoted by the relevant parameter. print(h.readline()) If a new file called “mytestfile.txt” is to be created, then the code would be: will read the first two lines in your practice file. This h = open("mytestfile.txt", "x") means that the output will be: This expression will create a file called “mytestfile.txt” This is my practice file. but if the file already exists an error message will be returned. If this happens then the new file name will The file is for practice. need to be changed. 23 346789_C02_DD_TLevel_Core_014-054.indd Page 24 04/08/22 6:40 PM F-0250 /101/HO02419/work/indd Digital Production, Design and Development T Level: Core The expression to create a new file called “mytestfile. if the file name does not already exist. To write to txt”, if the user is sure this file name does not exist, is: an existing file, in this case practicefile.txt, the code h = open("mytestfile.txt", "w") would be: h = open("practicefile.txt", "w") Writing to a file h.write("The contents of the file There are many occasions when an existing file will have been totally changed.") need to be appended or edited. It is important to use the correct file name when writing a file. If the h.close() incorrect file name is used, then this will result in the incorrect file’s contents being changed. # Open and read the file after the To write to an existing file the open() notation is changes: used. The mode required is denoted by the relevant parameter. The parameters are shown in Table 2.10. h = open("practicefile.txt ", "r") The “a” parameter is used to append the contents print(h.read()) of a file. This parameter will also create a new file if the file name does not already exist. To append an The output of the code will be: existing file's, in this case practicefile.txt, the code The contents of the file have been would be: totally changed. h = open("practicefile.txt", "a") The original contents of the practicefile.txt have been h.write("Another line has been overwritten. So, instead of having four lines of text as added.") output, there is now only one line. h.close() Test yourself # Open and read the file after the 1 What is the purpose of the Python parameter “w”? appending: 2 Write Python code to read the first 12 characters in a file named “TestYourself.txt”. h = open("practicefile.txt ", "r") 3 What is the difference between writing a file and appending a file in Python? print(h.read()) 4 Write the Python code to add “This is question 4” to the file named “TestYourself.txt”. The code uses a comment to explain the code purpose. 5 Which parameter is used to create a new file? This is defined with a “#” at the start of the comment. Comments are covered in section 2.7.1 of this content area. 2.4 Program structure The output of the code will be: 2.4.1 Using sequence, selection This is my practice file. (branching) and iteration within The file is for practice. programs and algorithms An algorithm is a set of step-by-step instructions used I hope it works! to solve problems. There are three constructs to use Another line has been added. when designing an algorithm: sequencing As well as editing the contents of a file, it is possible to selection overwrite the contents with new contents. iteration. The “w” parameter is used to overwrite the contents These are the required building blocks which help of a file. This parameter will also create a new file to describe solutions in a format that is ready for 24 346789_C02_DD_TLevel_Core_014-054.indd Page 25 04/08/22 6:40 PM F-0250 /101/HO02419/work/indd Content area 2: Introduction to programming programming. It is important to remember that algorithms contain steps and programs contain Activity statements. Create pseudocode for: Sequence The program asks the user “How old are you?” Sequences are the main logical structure of When the user inserts their age, the program algorithms and programs. The sequence of actions displays “You age is” + age (where + age is the age must be appropriate and run in the order that they input by the user). are presented. No instruction can be skipped. There is no restriction to the number of instructions within a sequence as long as the rules are followed. Selection (branching) Consider the actions you take when you wake A selection is used when a program needs to ask a up in the morning and you get up to go to school question or make a decision, because it has reached a or college. An algorithm can be represented as stage where there is more than one option available. flowcharts or pseudocode. Sequences follow a Therefore, depending on the answer/decision ‘sequence’ of actions in a specific order. provided, the program will follow a particular step and ignore the other steps available. Selections are Action important as they allow there to be more than one path to follow within a program. Without the option 1 to use selections within a program, there would not Action be the potential to take different paths. This would 2 result in the created solutions not being realistic. Action START 3 Action INPUT 4 “What is your age?” ▲ Figure 2.1 A sequence of actions for an algorithm YES OUTPUT Is age >=18? “You are of the correct age to proceed” START NO OUTPUT INPUT “You are too young to STOP “How old are you?” proceed” ▲ Figure 2.3 A flowchart for the selection process age = integer Iteration OUTPUT Iteration is the process where a set of instructions “Your age is” + age are repeated in a sequence a set number of times or until a predetermined condition is met. When a set of STOP instructions are completed and then executed again, this is called an iteration. Iterations simplify algorithms ▲ Figure 2.2 Example of a flowchart to represent an by stating that predetermined steps are repeated as algorithm using a sequence required. 25 346789_C02_DD_TLevel_Core_014-054.indd Page 26 04/08/22 6:40 PM F-0250 /101/HO02419/work/indd Digital Production, Design and Development T Level: Core A simple example of an iteration 4 Pour milk onto the cereal in the cereal bowl. A person is having cereal for breakfast. This is the 5 Use spoon to pick up cereal from bowl. algorithm that could be created with the iterative steps 6 Put spoon in mouth. for eating the cereal. 7 Use mouth to remove cereal from spoon. 1 Remove cereal bowl from the cupboard. 8 Chew cereal and swallow. 2 Remove spoon from the cutlery drawer. 9 Repeat steps 5 to 8 until all cereal and milk in cereal 3 Put cereal in the cereal bowl. bowl has been eaten. 10 Wash up empty cereal bowl and spoon. Test yourself 1 Give an example of a simple iteration (without using password. The password must contain the examples provided in this section.) at least one capital letter, one number 2 Identify the three constructs used when designing and a special character. If the customer an algorithm. does not create a password complying 3 Describe how a sequence works. with these rules, they receive an error 4 What is an iteration? message informing them that the 5 Use pseudocode to represent an algorithm for a password is not acceptable. If they create customer setting up an online account: a password that complies with the rules, A customer is setting up their online their details are stored and they receive account. Their email address is their a message informing them that their username and they have to create a account has been created. 2.4.2 Write and interpret code that It is important to take your time and make sure that makes use of sequence you read every line of your code carefully so that you can interpret what sequence of actions are taking place. As previously stated, sequencing is the order in Ask yourself: which the program code (statements) is executed. Are the actions in a logical order? This means that If the sequence is not in the correct order, then the code that you have written is in the correct the program will not function as intended. So it order for performing calculations, carrying out is important that you have a good understanding processes etc. of what the program is for (the purpose) and the Has the code been written in the most efficient sequence that the code must follow. For example, and effective way? Efficient usually means that the you write code to ask someone to input their age and code is ‘correct’ and follows standards and accepted print them out a message that includes their age. If approaches when writing sequences. Effective you wrote a sequence that called for the action of means that it will achieve the desired outcome(s). printing the age, before it carried out the action of Even when taking extreme care when writing code, it asking for the users age, it will not work. How can it is easy to make a mistake. If professional programmers display the message and the user’s age before it even can make mistakes. Python has an interactive interpreter knows what it is? This is where pseudocode is useful (IDLE). IDLE is the Integrated Development Learning as it helps you to plan the sequence of actions that Environment which is included in the installation of needs to take place. So there are two key points Python. The IDLE is useful for identifying mistakes such to remember: as syntax and runtime errors. There is however another What is the purpose of the sequence (what do you type of error referred to as a logic error. This occurs want to happen)? when a program doesn’t do as intended even though What is the sequence (the steps of the process to it appears to be a valid program. These logic errors can follow) to achieve the final output? cause unexpected results referred to as bugs. When you Having the instructions in the wrong order is a identify and rectify these bugs it is known as debugging. common mistake by programmers, regardless of the To help you debug a program, you use a tool known as programming language they are using! a debugger. This is a useful tool that helps you identify the bugs and understand why they have occurred. 26 346789_C02_DD_TLevel_Core_014-054.indd Page 27 04/08/22 6:40 PM F-0250 /101/HO02419/work/indd