Transcript for:
Key Concepts in GCSE Computer Science

Hello, this video contains all content from the J277 OCR GCSE computer science specification for paper 2, which is called computational thinking, algorithms, and programming. There is a separate playlist for each individual topic, but this video contains more than one place and in just over an hour, including all of the programming concepts you need to know with examples. [Music] Abstraction is one of the three principles of computational thinking which are used to solve complex problems. Abstraction is the process of simplifying a problem by ignoring irrelevant data and focusing only on the most important details. Abstraction helps to simplify a complex problem. When programming, abstraction makes it easier to understand, maintain, and reuse code. Inbuilt functions like sort and rand are examples of abstraction. The sort function will sort a list of values, hiding from a programmer the knowledge of how it works or which sorting algorithm is actually being used. Rand int generates a random whole number without showing the programmer how as they don't need to know. This allows them to focus on more important parts of writing the program. An exam question may present a scenario and ask you to consider how abstraction can be used. Here is an example of how three different people can use abstraction with a school student database, showing the data each person will focus on and what they can ignore. For example, a teacher needs to know the test scores and grades of their students, but they don't need to know their dietary requirements. Decomposition is one of the three principles of computational thinking which are used to solve complex problems. Decomposition is the act of breaking down complex problems into smaller, more manageable sub problems that are easier to solve. It is easier to understand, debug, and create solutions for several smaller problems than one very large complex problem. Also, working on more manageable sub problems can speed up development. Team members with specific strengths can work on separate sub problems at the same time. Once code for a sub problem is complete, it can be reused in other parts of a program. Video games are an excellent example of how decomposition can be used to break down a very complex problem of creating a level or world in a video game into more manageable components like handling player inputs and managing inventory and player stats. Developers can work to their strengths on individual sub problems and when all are finished they can be put together to form a complete solution. [Music] Algorithmic thinking is one of the three principles of computational thinking which are used to solve complex problems. Algorithmic thinking is the process of designing a step-by-step plan or set of instructions to solve a problem. Each task is broken down into logical steps that can be followed. There are three ways to write an algorithm that you need to know. Writing pseudo code, drawing a flowchart, and writing in a highle programming language like Python or Java. Each of these methods has its own video in section 2.1.2. Pseudo code is a way of writing informal instructions in a codelike format. There's no specific way to write it, but it should be clear and unambiguous, so it can be easily translated into any programming language. A flowchart is a visual way of representing the steps in an algorithm using specific shapes. It helps programmers to plan the flow of data for a program and communicate to others how it will work. Programmers use highle programming languages like Python and Java to write code that is translated into a format the CPU can understand and execute. In an exam, you may be asked to identify the inputs, processes, and outputs in a given scenario. This refers to data and not devices like keyboards for input or monitors for output. Inputs are data entered into a system. This can be manually entered by a human such as typing on a keyboard or automatic such as a temperature sensor. Processes are the actions taken by a computer often using the input data. For example, validating the data has been entered correctly or performing calculations. Outputs are information provided to the user after processing. For example, displaying the result of a calculation. Here is an example scenario to consider the inputs, processes, and outputs of a university library checks books out using a computer system. Students can loan a book for two weeks at a time. Potential inputs include the student ID, the book ID, and the date of the loan. Processes in this scenario could be checking if a book is available, recording the loan in the system, updating the book's availability, and calculating the due date for it to be returned. And outputs include a confirmation message, the updated book status, and a due date for the book's return. Here is another scenario. Customers can book a hotel room online. They can book single or double rooms and have 10 days to cancel a booking. If you want to have a think, you can pause the video now before I put up the inputs, processes, and outputs that I thought of. Inputs include the customer's name, check-in, checkout dates, and room type. Processes, I've got checking, room availability, and calculating the total cost. And for outputs, I've got things like booking confirmation, receipt with details. Structure diagrams display the organization or structure of a problem in a visual format, showing its subsections and how they link to other subsections. Structure diagrams are an example of decomposition and can be used to plan a new program. They are not the same as flowcharts, which use specific shapes and depict data flow and logic. Here is an example of a structure diagram showing the subsections of a game of knots and crosses, also known as tic-tac-toe. It does not show the flow of data, but displays how the program is broken down into different subsections and further processes within these subsections. This example shows a simpler structure diagram for a mobile game with the key subsections. Remember, these types of diagrams present the structure of a problem rather than any specific code. Here's a structure diagram for a running app to input, view, and remove race times. You may be asked in an exam to draw a structure diagram for a given problem or more likely fill in a partially complete structure diagram by carefully reading the context provided in the question. Pseudo code is a way of writing informal instructions in a codelike format. There's no specific way to write it, but it should be clear and unambiguous so it can be easily translated into any programming language. While there isn't a particular way to write pseudo code, it should still be precise enough that programmers can easily turn the algorithm into a highle language like Python or Java. The problem with the top pseudo code example here is that calculate is too vague and isn't actually a command. The pseudo code should show how the average would be calculated. Pseudo code has no standard formatting, but there are still some general rules that you should know. Input and output lines are separate. Casting is not generally shown when inputting numbers. The command then is used instead of a colon. Brackets are not required when using output and if statements are closed with end if. Four loops will end with next and while loops will end with end while. Some questions in the exam will ask for an answer in pseudo code. These are generally smaller questions in section A and can also be answered in different ways, including a highle programming language like Python. For more information about writing code in the exams, see the 2.1.2 video on this topic. A flowchart is a visual way of representing the steps in an algorithm using specific shapes. It helps programmers to plan the flow of data through a program and communicate to others how it will work. There are five flowchart shapes you need to know. You must use these specific shapes in an exam. Each will be explained in turn. All flowcharts must start and end with a terminal. This shape is also known as a terminator. A parallelogram is used to input and output data. In Python, asking for and inputting a value would be one line of code, but flowchart separate this into an output and then input. A rectangle represents a process. Examples of processes include assigning a value to a variable, performing a calculation, and randomizing a number within a given range. A diamond represents a decision made with an if statement. The two outgoing flow lines are typically labeled with true and false. A rectangle with two vertical lines represents a subprogram, which is a functional procedure. Any parameters, for example, num or name, are included within the rectangle. When a subprogram is called, it activates a separate flowchart with new terminals. The subprograms flowchart is followed and when complete, progress continues from where the subprogram was called. Instead of start, the opening terminal for a subprogram is its name and any parameters. A procedure does not return a value, so it uses a standard end terminal. A function is a type of subprogram that returns a value, so it can be used elsewhere in the program. The ending terminal of a function states the value to be returned. Arrows in a flowchart are called flow lines. All shapes typically have one outgoing flow line except decisions which have two and the end terminal which has zero. You may be asked to read a flowchart to understand its purpose or outputs. You may also be asked to finish an incomplete flowchart or to draw one from scratch. This example here inputs and multiplies a number. A for loop can be represented by using a count variable which can be named anything and a decision. This example repeats 10 times printing the numbers 1 to 10. A while loop can be represented with a decision that loops back to a previous part of the flowchart. This example loops while the password input is not 1 2 3. The second exam is split into two sections. Section A is a mix of theory questions and shorter programming questions that can be answered in many different ways. OCR recommends you spend 50 minutes on section A. Section B is also a mix of theory questions, but with more complex programming questions, too, but may require answers in OCR exam reference language or a programming language only. OCR recommends you spend 40 minutes on section B. Theory topics here refers to the parts of the specification that are not writing code such as computational thinking, testing, and IDE tools. In terms of actually writing code, you can generally expect a few short programming questions and several five or six mark programming questions too. The rest of paper 2 will cover the other topics in the specification. There should not be an overlap of any topics from paper one such as networks, laws, or the CPU. OCR exam reference language is a type of pseudo code created by OCR that they will use in exams to present code. You need to understand it, but you don't need to write in it if you prefer to write in a language that you've learned like Python or Java. This isn't a real language and it wouldn't work if typed into a development environment. But you can see here in the example that is quite similar to Python. Section 3C in the specification document lists all the OCR exam reference language you need to know. And there's more about this later in the video. The first section of paper two focuses on theory topics, but we'll have some shorter programming questions that can be answered in a range of different methods. If you see write an algorithm, that means you can use any of the accepted formats here, which we'll look at in the next slide. Here are the accepted methods for writing algorithms, unless the question clearly asks you to respond in a specific way. Every algorithm here represents the same problem. entering a number, multiplying it by five, and outputting the result. You can see that Python and OCR exam reference language is similar. Pseudo code is unambiguous codelike statements. Flowcharts have a separate video as you may be asked specifically to create a flowchart for a scenario. Finally, you can respond in bullet points and or natural English statements as long as they are not too vague. Remember to read the wording of the question very carefully. If in doubt, program code like Python should be accepted for every type of algorithm question, including if it asks for pseudo code. Some questions in section B will clearly state they must be answered either in OCR exam reference language or a programming language like Python or Java. Other methods will score no marks. However, some section B questions may allow pseudo code or flowcharts. So, it's very important you always read the question carefully. Here is a list taken from section 3C of the specification document of all the code concepts you must be able to understand and write code for potentially in the exam. I recommend to my students that they answer all programming questions in Python as that's the language I've taught them unless a question clearly asks for an alternative method such as a flowchart. All of these concepts are covered in both OCR exam reference language and Python in the videos in the 2.2.1 and 2.2.3 in 2.3 sections. A trace table is used to track the values of variables as they change throughout a program's execution. It helps programmers identify logical errors by showing how data changes step by step. Trace tables are often used manually during dry runs. That's when a programmer goes through the code line by line without running it on a computer. Tracing can be supported by IDE tools for debugging such as a variable watch or break points. IDE tools is the final topic of paper 2. Some general rules for using trace tables include that variable values only need to be shown when they change. Also, when using selection or iteration, it is unlikely that each line will be visited in order. Finally, only printed values will be shown in the output column. The second exam traditionally has one trace table question with a blank table for you to fill in. Usually the column headers are for the line number, the value of each variable in the extractive code and any output to be printed. Remember the code you see will be OCR exam reference language. The biggest difference to real code like Python being that loop ranges are inclusive. So 1 to three on line two means 1 2 and three, not one and two as it would with Python's exclusive upper range. Starting at the beginning of the code, make your way through and update the values of variables as they change. The for loop is now starting with I beginning at one. You will have gaps in your trace table as you only need to update it when a change has been made. Although you won't be penalized if you repeat a variable's value as long as it is the correct current value. No change has actually been made on this line, but a calculation has been performed. So, it makes sense to add a new line in the trace table. Next is a command in OCR exam reference language and other types of pseudo code that increases the value of the count in this case I by one ready for the next iteration through the loop. The loop has returned to the starting condition which is still valid as I is currently two. No changes have been made so there's no need to update the trace table. Be careful with recording your line numbers and don't absently keep counting by one each time. We're back on line three and now total is updated to four with two multiplied by two. Use what you've got from your trace table to track current values if any calculations are required. Next I increments the count by one to make three. Back at the start of the loop, I is now three. So we know it's the last iteration. Total's new value is now 12 as it was four. And multiplying that by the value of I, which is three, makes 12. The next I command increases I to four which is outside of the range 1 to three on line two. So the loop is now finished. With the loop complete, we've reached the final line which is a print line and that goes in the output column. It is important to practice completing trace tables. And remember that the code you see in exams will be OCR exam reference language like the extract here and not Python or Java. So I recommend you have a go with each trace table question from previous exams 2022 onwards of which there's usually one per paper too. A linear search checks each item in a list one by one from the start. It stops when it finds the target value or reaches the end of the list without finding a match. In this example, the target value is 8. 54 is not equal to 8. So it will move on to look at the value in the next index. 27 is also not equal to 8. Neither is 19. 8 is equal to 8 and the target value has been found stopping the search. Benefits of a linear search include that they all work on both sorted and unsorted data unlike a binary search. A linear search is also simple to understand and quick to code making it suitable for small data sets. However, a linear search is generally much slower and less efficient than a binary search. Linear searches may need to check every data item, which for large data sets could take a long time. You do not need to memorize for the OCRGCSE any searching or sorting algorithm code. But you may be shown some code and asked to identify which algorithm it is. For a linear search, a loop, which could be for or while, is used to search through the length of a data set, stopping when the target is found. Reaching the end of a list without a match will indicate the data is not present. A binary search has a prerequisite, which is a condition that must be met before the algorithm will work correctly. The prerequisite of a binary search is that the data must be sorted. A binary search is an example of a divide and conquer algorithm that repeatedly splits data sets in half to reduce the amount of searching required. A binary search finds the midpoint of the data and compares it to the target value. It continues to split the data set in half until the target is found or there's nothing left to search. You probably won't see the index values given to you in an exam, but I've added them here to help in calculating the midpoint. The index of both the lowest and highest values are identified and tracked as variables. These are used with integer division to calculate the midpoint. The midpoint is calculated by adding the index of a low point to the index of a high point. But 0 + 7 is 7. Divide this by 2 is 3.5. Integer division removes any decimal places after division and that becomes three. So the midpoint is three which is 22. If that was confusing, a less technical way to work out the midpoint is to count how many values remain and divide this by two and then round down if you need to. So here there are eight values. Divide this by two and the midpoint will be the fourth value along. The target value is compared to the midpoint and there are three checks that take place. If the target value is less than the midpoint, then you will ignore the upper half of the list. If the target value is more than the midpoint, then you'll ignore the lower half of the list. And if the target value is the same as the midpoint, then the target has been found and the search can stop. In this example, we are searching for 40 and 40 is greater than 22. So the lower half can be ignored as it cannot possibly be located in that half. That is why sorting the list is a necessary prerequisite so that it isn't accidentally ignored. A new midpoint is calculated every time the list is halfed. First, the new low point and high point are identified. The new midpoint is in index 5. That's because the low point four is added to the high point 7 to make 11. 11 / 2 is 5.5. And with integer division, the decimal is removed for just five. Alternatively, you could see that there are four values remaining. Divide this by two and you get two. So the midpoint is the second value along which is 34. 40 is greater than 34. So the list is split in half again and the lower half is ignored. Identifying the low and high points this time is straightforward. And the midpoint is 6. 6 + 7 is 13. 13 / 2 is 6.5. Into division will change that to just six. Alternatively, you can see there are only two values left. 2 / two is one. So the first value is the midpoint, which is 40. Index 6 is both the low point and the midpoint. The target value and the midpoint are the same. So the search has been successful and 40 has been located in index 6. The main benefit of using a binary search is that it's generally much faster and more efficient than a linear search, especially for large data sets as it does not need to compare each value sequentially. However, data must be sorted before a binary search can be used or it may not find a value correctly. Also, it is a slightly more difficult algorithm to write than a linear search. In the OCRGCSSE, you do not need to memorize any searching or sorting algorithm code, but you may be shown code and asked to identify which algorithm it is. The two main clues for identifying a binary search is that you should be able to spot a midpoint, low point, and high point being calculated. Also, a while loop will be used to repeatedly compare the midpoint to a target value. [Music] A bubble sort repeatedly compares adjacent values and swaps them if they are in the wrong order. A bubble sort uses a flag, which is a boolean variable to track if the swap has been made in the current pass through the list. The sort finishes when a pass is completed with no swaps being made. That would be the flag staying false. Let's look at how a bubble sort works on this set of data to sort it into ascending numerical order. Adjacent pairs are compared and swapped if they are not in the correct order. 8 and 12 have been swapped because 12 is larger than 8. When a swap occurs, the flag is changed to true. This is used at the end of a pass to check if another pass is required or if the list is sorted. The next two values are compared. Be careful not to accidentally skip ahead. For example, checking seven and 16 instead of 12 and 7. 7 and 12 are swapped over. The flag remains true after the first swap of a pass until the end of that pass. The next two values 12 and 16 are compared. These are in the correct order, so no swap is required. 16 and 10 are compared and need to be swapped. The final comparison of the first pass is 16 and 11, which requires a swap. At the end of the first pass, it is guaranteed that the largest value will be sorted to the end of the list. The flag is checked at the end of each pass. If it is true, it means at least one swap occurred during that pass. So the list may still be unsorted and another pass is required. If no swaps occurred and if a flag is false, then the list is sorted. If you are asked to show how a bubble sort works on a given set of data and that can be numerical or alphabetical in an exam, you don't need to show every individual comparison. Each swap is recommended or at least showing each pass. At the start of each new pass, the flag is reset to false, and the comparisons begin again from the first pair of values. 8 and seven are compared and need to be swapped. Making this swap changes the flag to true. No swap is necessary for 8 and 12, but 12 and 10 are in the incorrect order and need to be swapped. And 12 and 11 also require swapping. The final comparison of pass 2, 12, and 16 does not require a swap. In this example, we can see that this list is now sorted because it's a very small data set of only six values. However, because the flag is true, the algorithm must start again for one final pass to ensure it is fully sorted. A bubble sort algorithm only stops when the flag is false at the end of the pass, confirming that no further swaps are required and the list is sorted. The flag is reset to false and each pair is compared in turn. In this pass, no swaps are required. Completing a pass with a flag still at false is the stopping condition of a bubble sort and the list has been sorted. An advantage of a bubble sort is that is simple to understand and program. However, a bubble sort is usually much slower than both an insertion sort and a merge sort, especially for larger data sets. You do not need to memorize any searching or sorting algorithm code, but you may be shown code and asked to identify which sort or search it is. And remember, there's no one way to write a bubble sort either. But some of the clues you're looking for include a flag to check if values have been swapped, swapping adjacent values, for example, array i equals array i + 1, and an outer while loop with an inner for loop. The outer loop continues until the flag is false, and the inner loop cycles through the list from the start to the end to compare each pair in turn. [Music] A merge sort divides a list in half again and again until each data item is separate. This type of algorithm is called divide and conquer and it is efficient for large data sets. It then merges each sublist back together, comparing values and putting them in the correct order. This process continues until there is only one fully sorted list. Here is another example of a merge sort. This time sorting the characters into ascending alphabetical order with an odd number of items. Just be consistent when dividing and merging. Merge sort is highly efficient and is usually much quicker than bubble and insertion sorts, especially for sorting large data sets. However, it is more complex to program and it uses more memory. You do not need to memorize any searching or sorting code, but you may be shown code and asked to identify which algorithm it is. Algorithms can be written in many different ways. The extract of a merge sort below is just one potential method. Some clues for identifying a merge sort include that it divides lists into a left side and a right side. It splits until there's a length of one and the algorithm calls itself. This is known as a recursive algorithm. Recursion is a concept in Alevel you don't need to know for GCSE. But you might be able to see on line seven and 8 that the merge sort is calling itself to repeatedly split lists in half. With an insertion sort, the list is divided into a sorted and unsorted section. Starting from the left, each value from the unsorted section is compared to items in the sorted section and inserted into its correct position. The list's first value is regarded as the beginning of the sorted section. The first value in the unsorted section is compared to this sorted section. After each insertion, the next value in the unsorted section is compared and shifted into its correct position in the sorted section. An insertion sort is efficient for small data sets and usually faster than a bubble sort, but it becomes slow for large lists compared to more advanced algorithms like a merge sort. You do not need to memorize any searching or sorting code, but you may be shown some code and asked to identify which algorithm it is. Remember that algorithms can be written in many different ways. So the extract here is just one potential method. Some of the clues of identifying an insertion sort include an outer for loop to iterate through each value, an inner while loop to find the next unsorted values correct position and it moving backwards to find the correct position. You can see on lines five and 8 that the variable decreases by one. This is in contrast to a bubble sort where it will move from the left to the right through the list of values. [Music] You must be able to read OCR exam reference language as this is how code will be presented in the exam. You also need to have experience writing in a highle programming language such as Python or Java. Let's look at comments, variables, and input and output. We'll also cover constants and casting. A comment is not printed when a program runs. It can be used to describe a purpose of code and is helpful for working in teams. OCR ERL uses two forward slashes whereas Python uses a hash. A variable is a named memory location that stores data that can be changed as a program is being executed. A constant is a named value that cannot change as a program is being executed. A single equals is used to assign a value to a variable. The variable name known as the identifier is written first and then the value. Strings, which are a collection of letters, numbers, and/or symbols, require speech marks. Integers, which are whole numbers, and real or float values, which are decimal numbers, do not use speech marks. The available variable in this example is boolean, which is true or false with a capital letter. A constant cannot change in value as a program is being executed. Python does not use constants. The const command denotes a constant is being used in OCRL. For Python, you could use a variable to act like a constant and just not change it. The input command allows the user to enter data. OCRL does not require casting into different data types. With Python, data is automatically input as a string. If you require the data to be treated differently, such as performing a calculation on a number, you will need to cast it into a different data type. Int is to convert it into an integer, float is for a decimal number, and bool is for a boolean value. str also exists to convert a value into a string. The print command outputs the contents of the brackets. Speech marks are used for strings. A comma or a plus sign breaks up a sentence. A comma adds a space between parts of a sentence when printed and the plus sign does not. Using a plus sign is called concatenation. See the string handling video for more information about this. [Music] There are three basic programming constructs to control the flow of a program. First of all is sequence. In a sequence, each instruction is executed one after the other in a logical order. Sequencing is important to ensure that programs work and output data as expected. The second example here would give an error as total cannot be printed on line three if it is not assigned a value until line four. [Music] There are three basic programming constructs to control the flow of a program. Selection refers to making decisions. There are two main methods of using selection to make decisions, but we will look at in both OCR ERL and Python. OCRL uses then and doesn't require colons. It uses end if to denote the end of the if statement. Selection uses double equals to represent equal to. Any indented code beneath an if statement will be run if a condition is true. If it is false, then the indented code beneath else will be run instead. Else if or LF can be used for additional decision-m. There is no limit to the number of L if statements that can be used. The program will look at the if statement first and run the indented code if the condition is true. It will then look at each else if statement running the indented code of the first statement that is true. If none of the conditions are true, it will run the else code instead. Switch case is an alternative form of selection. If and lf are replaced by case and else is default. Python's version is match case. Switch or match is the data to make a decision about. In this example, it is the value of the variable planet that has been input. Each case is compared to the switch in turn and it will run the indented code of the first that is true. If no cases are correct, default will run instead. This is the same as an else statement in if then else selection. An if statement inside of another if statement is called a nested if. In this example, if num one is more than 10, a second number is input. Another if statement is used within the original if statement to see if a second number is also greater than 10. Nested ifs can be confusing to write. So make sure any corresponding if, lif, and else statements are indented so that they align vertically. There are three basic programming constructs to control the flow of a program. Iteration is when code is repeated through the use of a loop. There are three types of loop that you need to know, although only two of these can actually be used in Python. A for loop is a count controlled loop which repeats a specific number of times. OCR erl has an inclusive upper range and Python's is exclusive. So 1 to 10 in OCR ERL means 1 2 3 4 5 6 7 8 9 and 10. 1 to 10 in Python would actually only go to 9. So you have to write 1, 11 to include 10. A step denotes by how much the loop variable will increase or decrease with each iteration. The step is inclusive in both OCRL and Python. The first example prints the eight times table 8, 16, 24, etc. up to 80. The second example prints 100, 99, 98, etc. down to one. A while loop is a condition controlled loop that repeats as long as the condition is true. Exclamation marks equals means not equal to. This example will check the value of the answer variable. And while it is not equal to Nairobi, we'll repeat the indented code, which is to input a value. When the condition is no longer true, so when the answer is equal to Nairobi, the loop finishes and moves on to the next line to print correct. Here is another example of a while loop. It repeatedly inputs numbers and adds them to a total as long as the total is less than 100. While true loops are not covered in the OCR specification, but they are a valid and helpful alternative method of writing a while loop. A while true loop will repeat until it reaches the break command. True is a boolean value, so it requires a capital T. A do until loop is another example of a condition controlled loop. The condition is checked at the end rather than at the start. Do until loops are not used in Python. A major difference between a while loop and a do until loop is that because the condition is at the end, a do until loop will run the indented code at least once. Whereas with a while loop, if the condition is already false, the loop will not run at all. A loop within another loop is called a nested loop. In a nested loop, the inner loop runs to completion every time the outer loop runs once. You can see the J loop runs from 1 to three while the I loop is at 1. Then it runs from 1 to three again while the i loop is at two and then again when i is three. There are three categories of operators that you need to be able to understand in OCRL and code in a programming language like Python or Java. Comparison operators are used to compare values often with selection or iteration. It is vital that you don't make a silly mistake such as getting your less than and greater than signs mixed up. Arithmetic operators are used with numerical values such as an integer or real. Add, subtract, multiply, and divide are the four that you need to know. There are three more complex arithmetic operators that you need to know. Modulo gives the remainder after division. Quotient or integer division removes any decimals after division. And an exponent is to the power of. For example, 5 up 3 is the same as 5 ^ 3 or 5 * 5 * 5. Let's look at the Python examples on the right hand side here. 20 mod 3 is 2. If we look at 3 going into 20 3 6 9 12 15 18 21 is over 20. So from 18 to 20 the remainder is 2. 20 integer division 3 is 6. 20 / 3 is 6.66. 6666 recurring. Remove the decimal and you are left with just the integer 6. Finally, with exponentiation, 20 star sign star sign 3 is the same as 20 to the^ of 3, which is the same as 20 * 20 * 20, which is 8,000. Boolean operators are used to check the logic of a statement. The and operator is used in the first example to check if both the username and the password are equal to specific values. The second example uses the or operator to check that at least one of the two parts of the condition is correct. That the answer is either equal to Japan or equal to South Korea. It's important to note that even if you are using the same variable, you must write its name out again. If answer equals Japan or South Korea would not be correct. It must be if answer equals Japan or answer equals South Korea. Finally, the not operator reverses a condition. So if not guess equals yellow is the same as if not equal to yellow. A data type defines the kind of data a value represents. Variables can be assigned a data type and changing a value's data type is called casting. The five you need to know a character, string, integer, real, and boolean. A character is a single letter, number or symbol. A string is a sequence of characters. You can see in these examples that speech marks are required for both strings and characters. An integer is a whole number. It can be positive or negative. A real or float is a decimal number which again can be positive or negative. Integers and reals do not need speech marks when written in a programming language. A boolean value is either true or false. It requires a capital letter and does not use speech marks. Converting a value to a different data type is called casting. Casting is often used when inputting data to convert the value to a data type other than a string. You can see the different types of casting that you need to know are int, float, bool, and str to represent converting into a string. There are several concepts to do with string handling or string manipulation that you need to know for OCRL and in a programming language like Python or Java. The length or len command returns the total number of characters in a string and that includes spaces which is counted as a character. Extracting only certain parts of a string is called slicing. Characters in a string are zero indexed. Each character in a string has an index and this starts at zero not one. In OCRL substring can be used to extract certain characters. The first number in this example five is the index of the character to start with and the second number is how many characters to include. In Python square brackets can be used in a similar way. The extract will start on the character with the index 5 just like OCR but the second number refers to which character to extract up to except Python uses an exclusive range. So 11 will actually stop on the 10th character which is t. The left command in OCRL prints a specific number of characters from the start of a string. This can be recreated in Python with the first value is zero and then the second value being the number of characters to include as three will print the values in indexes 0 1 and two. The write command in OCRL prints a given number of characters from the end of a string. To recreate this in Python, you can write the number of characters as a negative and then an empty value after the colon. So it will go to the end of a string regardless of how many characters are in that string. Adding strings together using the plus symbol is called concatenation. Using the plus symbol does not include a space like using a comma would upper and lower can be used to change the case of a string. Python requires empty brackets. Ask or or in Python converts a character into the dinary equivalent in the asky character set. CHR converts the dinary value into an ASKI character. Character sets are logically ordered. So printing as or capital C would return 67 and printing CHR 999 would print lowerase C. You do not need to know any ASI values for the exam. Storing data in a text file allows it to be stored longterm. Unlike arrays or lists that will not save their contents when the program is restarted. Data can be written to and read from a file. You need to know how to open, close, read from, write to, and create a new file. Let's look at how to do this in both OCRL and Python. A file must be opened before it can be used. Python requires the name of a file and then the open mode and that is R to read, W to overwrite and A to append to the end of a file. In OCRL, there is no open mode and when you use the right line command, you can presume the data would be added to the end of a file. Students often forget to write code to close a file in an exam and may drop a mark. The OCRL pseudo code above uses a while loop to print each line of a file until the end of a file is reached. Python doesn't have this command, but a for loop can be used to print each line. With Python, the open mode is R for reading. In OCRL, the new file function creates a new file. This will still need to be opened. In Python, the open command can be used to create a new file if a file of that name does not exist in the location where the Python file is saved. This will work for either the W or A open modes. You must be able to understand and write code for using both one-dimensional and two-dimensional arrays. An array is a data structure that holds elements of the same data type. Arrays are always zerobased and they are static, meaning they have a fixed size that cannot change as the program is running. In OCRL, the array command will create a new array. Square brackets are used for arrays and lists. For example, array names for represents a new array called names with four items. Python does not use arrays, but lists can be used in a similar way. Lists are not static and can use different data types, but they are still zero indexed. An element in an array or list can be printed using its index. So print numbers four will print 55. The value of an element can be changed using equals. So numbers 1= 13 will change the value in location 1 from 12 to 13. Here are two methods of printing each element in a one-dimensional array. The first if you know the number of values in the array and the second more simply cycling through each item. Name is just a count of each item and could have any identifier such as I. The search for a match code uses a for loop and the index number to compare each item in the array to a specific value. A two-dimensional array is composed of rows and columns. A 2D array can be used to represent a database table which is a collection of fields and records. 2D arrays use two numbers for each element's index. The first number refers to the row. The second number refers to the column. So array numbers 4, 6 means that you have four rows 0 to 3 and six columns indexed 0 to 5. OCRL uses the row and column index within a single square bracket. Whereas Python uses separate brackets, one for the row and one for the column. Print numbers 24 would output 50. Numbers 31= 32 would change 73 to 32. To print a specific row, the first square bracket which represents the row is locked at a certain value such as zero. And the second bracket uses the loop number. So this would print numbers 0 0 the first time which is 56. Then it would print 01 which is 12. Then 02 for 93, 03 for 74, 04 for 55, and 05 for 16. printing the entire first row in the 2D array. A similar concept is used to print a specific column. The row bracket uses the loop number and the column bracket is given the column to lock. So printing I5 would print 05 for 16, 1 for 32, 25 for 82, and 35 for 66. The using selection example goes through the row with an index of two and checks for values that are greater than 50. So we would print the numbers 79, 51 and 82. You must be able to understand and use both types of subprograms which are procedures and functions. You also need to know how to use parameters and global variables. A subprogram or subruine is a self-contained section of code that performs a specific task. It can be reused multiple times as needed within a program. Subprograms are a form of decomposition, helping to break large programs down into smaller, more manageable parts. They can make code easier to read, reuse, test, and debug. And their development can be split between team members. There are two types of subprograms. A function returns a value so that it can be used elsewhere in the program. A procedure does not return a value. A subprogram must be called to be activated. When the procedure finishes, the program continues from the line it was called on. Python uses defaf to define both procedures and functions. A parameter is a value that is sent to the subprogram when it is called, allowing it to be used within that subprogram. In this example, there are two parameters num one and num two that are sent when the procedure addition is called and can be used within that procedure. A function uses the command return to send a value back to the line on which the subprogram was called. This example calls division which inputs two numbers and then divides and returns the answer. Writing a print statement around division when it is called means the returned value is output. The function's return value can be stored in a variable allowing it to be used later in the program. In this example, return value is a variable named answer. Rather than print the square function when it is called, it is saved into a variable also called answer which is used in a print statement. On the next line, there are two types of variables that you need to know. A local variable is declared inside a subprogram and can only be used within that subprogram. A global variable is declared outside of all subprograms and can be used anywhere in the whole program. Local variables use less memory because they are only created when their subprogram is called and when the subprogram ends, they're removed. Global variables stay in memory the entire time the program runs, which uses more memory but is useful for important data. If you've been following this video series in order, generating random numbers is now the last code concept that you need to know. The range of random numbers is inclusive for both OCRL and Python. Python requires the rand int command to be imported from the random library before it can be used. A real or float is a decimal number. Python can use uniform from the random library. The ranges again are inclusive. These examples show that a random number can be generated and printed directly without using a variable. In databases, a record is a collection of related data fields stored together as a single unit. Each record represents one item or entry. for example, a customer or product within a table. Records are rows in a database and fields are columns. Each field is made up of the same data type such as an integer for age. Because records have multiple fields, they can have multiple data types. Structured query language SQL or sometimes called SQL is used to manipulate data in a database with specific commands. It can be used in many ways such as inserting, removing, and updating data. But the OCR GCSE course just requires you to know how to use SQL to search for data using the commands select from and where. Select identifies the field names to be included in the search. From is the name of the table to search through and where is the search criteria. In this example, the name and species fields have been selected from the animals table where name is equal to max. and and or can be used with the wear command to further refine the search criteria. The star symbol can be used with select to identify all fields in the table. In this example, all fields have been selected. That's name, species, and age from the animals table where the species is dog or the age is less than four. Here are some common SQL mistakes that you want to avoid. Firstly, fields must be separated by commas when using select. Secondly, you've got to make sure that the capital letters match the field and table names shown for you. And you have to use a single equals for equal to, not a double equals like you would the selection in Python. Also, you must repeat the field name after an operator. For example, where age is greater than one and less than five is not correct. It must be where age is greater than one and age less than five. To ensure that a program is secure and robust, meaning it is able to handle all likely input values, programmers use these techniques known collectively as defensive design. Developers must plan ahead to take steps against potential misuse of their program or system. For example, putting measures in place to stop a user from accidentally breaking a program or hacking into a system. Authentication ensures only authorized users can gain access to a system. Common methods include usernames and passwords, biometric recognition, and two factor authentication. For example, requiring a password and then a pin code which might be sent to a phone. Input sanitization means to clean up data that has been input, removing invalid or special characters. It may remove accidental spaces or speech marks and can also prevent SQL injections by removing any SQL commands. Validation is used to check whether the data that has been input follows specific criteria and should be accepted. You can learn more about validation checks in the next video in this series. Maintainability refers to allowing other programmers to understand the code. For example, using comments, indentation, and meaningful variable names. You can learn more about maintainability in the video after the next video in this series. Validation is used to check whether data that has been input follows specific criteria and should be accepted. There are six types of validation check. We're going to look at a range check checks that numerical data is within a given range. In this example, only people who are 14, 15, or 16 years old, that's year 10 to 11, can sign up for a basketball tournament. So 15 would be accepted, 13 and 17 would not, and 14 would be accepted in this range check. A type checks that the data is a certain data type. In this example, the shoe size has to be an integer. So seven is accepted because it's a whole number. But sen is a string so it's not accepted. 10 is accepted but 8.0 is a real or float value so it is not accepted. A length check checks the number of characters in the data. For example, a games company requires new usernames to be between 5 and 12 characters. The first three usernames here are all between 5 and 12, but the best gamer ever is more than 12, so it would not be accepted. A format check checks whe the data is entered in a specific way. A common type of format check is for an email address to make sure that you've got the at sign. In this example, a date of birth has to be written with day day/mon month/ year. So the first example is not accepted. The second example is you might think that the third example should be accepted, but the two middle values represent the month and there is no 14th month. And finally, the last value is not accepted because they've used four digits for the year when only two are accepted. A presence check checks that data has actually been entered and a text box has not been left blank. In this example, it is very obvious to see that there's only one data field here which has broken the presence check, which is the third one, because nothing has been written. A lookup check, sometimes called a table check, checks the data is from a table of accepted values. In this example, a restaurant only allows breakfast, lunch, and dinner to be selected. So, lunch and breakfast, the top and bottom values are accepted, but supper and diner would not be accepted because they are not within the table of accepted values. Programs should be written clearly so others can easily understand and update them. Writing maintainable code helps future programmers work on or improve the software after its initial development. Comments help a programmer to quickly understand the purpose of a section of code. This is crucial when working in a team and making improvements to someone else's work. Using subprograms to reuse code makes it easier to test and debug later. This is called modularity. Using appropriate variable names ensures the purpose of a variable is immediately understood. Naming conventions are often used for consistency too, such as camel case or snake case. Using indentation after selection, iteration, and subprograms will improve readability to show each section of code clearly. Although it's not shown in this example, using constants, which is data that will not change as the program runs, means that data can only be changed in one place, which helps with debugging and maintenance. Testing is done to ensure a program works for any input that is entered. It also checks a program meets the user requirements, works as intended, doesn't crash, and it can help identify errors to fix. There are two main types of testing. Iterative testing takes place during development. The programmer will write a module or subprogram and test it. Each module is refined and retested until it works as expected. Final, also known as terminal testing, occurs after development once all subprograms have been individually tested through iterative testing. It checks if a program as a whole works as expected. A syntax error is when the grammatical rules of a programming language are broken. A syntax error is detected by a translator preventing the program from being executed. Here are two examples. A spelling mistake and incorrect use of punctuation. A logic error results in an incorrect output or an unexpected result. A program contains an error, but it still runs and shouldn't crash. Two examples are an incorrect calculation and an incorrect use of an operator. Test data is used to test whether a program is functioning correctly. It should cover a range of possible and incorrect inputs, each designed to prove a program works or to highlight any flaws. In this example, we're going to look at the number of hours that somebody revised for the previous day. Normal data is sensible data that the program should accept and be able to process. So 2 hours of revision and 5 hours of revision are both sensible pieces of data in the correct data type and within a correct range. Boundary data is at the extreme boundary of any data range and it should be accepted. So 0 hours of revision and 24 hours of revision are both technically possible. Invalid data is of the correct data type but outside of a valid range and it should not be accepted. So 25 hours is impossible in a single day as is minus 1 hour. Erroneous data cannot be processed because it is of the wrong data type and should not be accepted. So O ne is not an integer. It is a string and 1.5 is a float or real value. Boolean operators are used to combine or compare boolean values. True representing one and false representing zero. They can be used to represent logical conditions and decision-making in programming. And the three that you need to know are not and, and or. Before we look at the three operators, you need to understand that a truth table is used to show all possible inputs and the associated output for each input. The number of rows needed in a truth table will double for each input. So in the top example, we have one input, which is A. So we need two rows. In the second example, there are two inputs A and B. So there are four rows. If there was a third input such as C, you would need eight rows. The not operator produces an output which is the inverse or opposite of the input. It is also known as negation and it can be represented using the squiggly symbol that you see there. The logic gate, if you were to draw a diagram using the not operator, is a triangle with a circle and that circle must be drawn for you to get a mark. Looking at the truth table, if a was input, not a is the opposite, so it would output one. And if a was one, not a would be zero. The and logical operator outputs one if both inputs are one. Otherwise, it will output zero. The operator is also known as conjunction and it can be represented using that symbol which looks like a capital A but without the horizontal line. The logic gate is a semicircle and the truth table shows that it will only output one if both a and b are one. Any other combination will output zero. The or logical operator outputs one if at least one of the inputs is one otherwise it will output zero. It is also known as disjunction and it can be represented using the upside down and symbol. The logic gate kind of looks like an arrow head. And the truth table shows that if there is at least one in either input, then it will output one. So the only time it will output zero is if both inputs are also zero. Let's have a go at completing a complex truth table to try and work out what a and not a or b would look like when represented. There are two inputs a and b. So we need to start by filling in the four different combinations 0 0 1 1 0 and 1 1. To fill in the not a column, we need to look at the a column and then use the not operator. Remember that is the opposite. So 0 becomes one, zero becomes 1, one becomes zero and one becomes zero. Now we look at the not a or b column. And you can see that we are going to compare the b column and the not a column in the previous columns. And we will use the or operator. So anytime there is a one, the output will also be a one. So zero or one is one. 1 or 1 is 1. Z or 0 is zero. And 1 or 0 is 1. Finally, we can now look at the A and not A or B column because there are brackets around not A or B. That is telling you that that is a previous column to look at. And we're going to compare that with the first column, which is A, and use the and operator between them. The AND operator will only output one if both inputs are one. So 0 and one is zero. 0 and one is zero. One and zero is zero. One and one is one. And now the truth table is done. What at first looked kind of scary was okay once you decompose the problem and just completed it column by column. Here is a reminder from a previous video of the logic gates for the free boolean operators that you need to know. Now we are going to use these operators to draw some logic gate diagrams. Here's a scenario. To have dessert, you must have eaten your vegetables and washed your plate. A represents having dessert. B represents eating your vegetables and C represents washing your plate. This expression can be represented as A equals B and C. You can only have dessert once you have done both B and C. You've eaten your vegetables and you've washed your plate. To represent this in a logic gate diagram, we need the and operators logic gate. And we've got our two inputs B and C going into it and our single output having the desert A coming out from it. Here is another scenario. A sprinkler system activates if it is hot and dry or if the safety switch is turned off. A represent it being hot. B represents it being dry. C represents the safety switch is on. And D represents the sprinkler is activated. In an exam, you can use the words and or or not or you can use the symbols as well. To show the logic expression here, I have showed the symbols because otherwise writing out would take up way too much room. So, let's look at this. The sprinkler is only going to be activated if it is both hot and dry or the safety switch is off. So, C represents the safety switch being on. So, we need to use not C to represent the safety switch being off. And this is what the logic gate diagram would look like. A and B or not C is equal to D. A highle programming language is much closer to natural human language making it easier to read, write, and maintain than a low-level language such as machine code. Highle languages are easier to learn and use and quicker to write and debug. They are also hardware independent, meaning they can be run and understood by different processes. For example, Python can be written on one computer and then understood and executed on a wide range of other devices. However, compared to low-level languages, they are often slower to execute as they need to be translated into machine code to be understood by the CPU. There's also less control over hardware and memory. Low-level languages do not resemble natural human language, making them harder to read and write. The two main types are machine code which is binary and assembly language which is not on the OCRGCSC specification. Machine code does not need to be translated so it is faster to execute than a highle language. Other low-level languages such as assembly are very quick to translate. Another advantage is that low-level languages allow a programmer to directly control specific hardware or a computer's memory. They can be optimized to use shorter code and take up less memory. However, low-level languages are more difficult for humans to read and write, making development slower and more prone to errors. They're also hardware dependent, meaning code written for one processor may not work on another system. A translator converts one language into another. Most often data is translated into machine code as that is the only format the CPU can understand and execute directly. The two types of translators that convert highle languages such as Python or Java into machine code are interpreters and compilers. An interpreter translates and executes code line by line. Whereas a compiler translates code in one go to produce optimized machine code. With interpreters, the program will need to be reinterpreted by the user every time it is run. However, compilers produce an executable file, so it does not need to be recompiled again each time it needs to be run. It is slower to execute interpreted code than compiled code and the interpreter must be installed on the user's computer. The compiler does not need to be installed by the user for the code to run. This means that the end user cannot see the source code which is good for security. Finally, the way that interpreters and compilers deal with errors is different and an interpreter will stop as soon as it encounters an error, whereas a compiler will report all the errors in an error file at the end of compilation. [Music] An integrated development environment or IDE provides programmers with many tools for creating, editing, debugging, and running programs. An editor allows highle program code to be entered and edited. It often contains additional helpful facilities such as automatic line numbering, automatic formatting, color coding, and statement completion. There are many different error diagnostic tools such as a debugger that are used to display information about an error when it occurs such as the line it occurred on and the error type such as syntax. A runtime environment enables program code to be executed on a computer system. It allows data to be input and output. It manages memory and can also report errors. Translators convert the highle language code the programmer has typed known as source code into machine code so it can be processed and executed by the CPU. The previous four IDE tools are listed in the OCR GCSE specification, but many other tools exist. For example, a break point. This is when a specific line is selected and the program pauses once it reaches it. Variable values can then be shown at that point. And a variable watch. This shows the value of specific variables as the program runs, helping to track changes and spot logical errors. IDE tools was the final topic. I hope you found this video useful and good luck in your exam.