top of page

Search CSNewbs

287 results found for ""

  • 4.6 - Graphical Representation - Eduqas GCSE (2020 Spec) | CSNewbs

    Learn about how images are represented in a computer system, including vector and bitmap graphics, file size, resolution, colour depth and metadata. Based on the 2020 Eduqas (WJEC) GCSE specification. 4.6: Graphical Representation Exam Board: Eduqas / WJEC Specification: 2020 + There are two main types of graphics used in computer systems: raster (also known as bitmap ) and vector graphics. Raster (Bitmap) Graphics Vector Graphics Raster graphics are made up of a grid of pixels . Vector graphics use objects (lines and curves ) to mathematically form shapes. If scaled to a larger size, a vector graphic does not lose any image quality . If scaled to a larger size, a raster graphic loses image quality . Raster graphics are generally larger in file size because data is stored for each pixel . Vector graphics are generally smaller in file size . Examples of raster images include photographs and screenshots. Examples of vector graphics include logos and cartoons. How to Calculate File Size File Size = Resolution x Colour Depth The resolution of an image is the width in pixels multiplied by the height in pixels. x The colour depth (also known as bit depth ) is the number of bits that are used to represent each pixel's colour . 1 bit represents 2 colours (0 or 1 / black or white). 2 bits will allow for 4 colours, 3 bits for 8 colours, 4 for 16 etc. A colour depth of 1 byte (8 bits ) allows for 256 different colours . Remember you must multiply the colour depth , not the number of available colours (e.g. 8 not 256). The RGB (Red , Green , Blue ) colour model uses 3 bytes (a byte of 256 red shades , a byte of 256 green shades and a byte of 256 blue shades ) that together can represent 16.7 million different colours. Example Height = 6 bits Resolution = height x width Resolution = 8 x 6 = 48 bits -------------------------- Colour Depth = 1 bit (only 2 colours) -------------------------- File Size = Resolution x Colour Depth File Size = 48 x 1 = 48 bits File Size in bytes = 48 ÷ 8 = 6 bytes File Size in kilobytes = 6 ÷ 1000 = 0.00 6 kilobytes Width = 8 bits Look carefully at the exam question to see if the examiner is expecting the answer in bits, bytes or kilobytes . Always calculate the file size in bits first then: Divide the file size in bits by 8 to convert to bytes . Divide the file size in bytes by 1000 to convert to kilobytes . Metadata for Graphics Metadata is additional data about a file . Common image metadata includes: Dimensions Colour depth Make Model Orientation Exposure time Metadata is important, For example, the dimensions must be known so the image can be displayed correctly . Metadata for a smartphone-taken picture: width in pixels, e.g. 720 height in pixels, e.g. 480 Q uesto's Q uestions 4.6 - Graphical Representation: 1. Describe three differences between raster (bitmap) and vector images . [ 6 ] 2. How many colours can be represented with a colour depth of... a. 1 bit [ 1 ] b . 5 bits [ 1 ] c. 1 byte [ 1 ] 3. How is the file size of an image calculated? [2 ] 4a. An image file has a width of 10 pixels , a height of 8 pixels and a colour depth of 2 . What is the file size in bytes ? [3 ] 4b. An image file has a width of 120 pixels , a height of 120 pixels and a colour depth of 1 . What is the file size in kilobytes ? [3 ] 4c. An image file has a width of 32 pixels , a height of 21 pixels and a colour depth of 1 . What is the file size in bytes ? [3 ] 5. State what is meant by metadata and give three examples of metadata for a graphics file. [ 3 ] 4.5 Character Sets & Data Types Theory Topics 4.7 - Sound Representation

  • 11 Graphical User Interface | CSNewbs

    Learn how to create and use a simple graphical user interface (GUI) in Python. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. Python 11 - GUI Graphical User Interface In Python, you don’t have just to use a text display; you can create a GUI (Graphical User Interface ) to make programs that look professional. This page demonstrates the basic features of Python’s built-in GUI named tkinter . You can add images, labels, buttons and data entry boxes to develop interactive programs . Hyperlinked sections covered on this page: Setup: Title, Size & Background Creating Elements: Labels, Entry Boxes, Buttons, Images, Message Boxes Displaying Elements: Pack, Place, Grid Inputs & Outputs GUI Tasks Setup Setup: Title, Size & Background Firstly, import the tkinter command and set tkinter.Tk() to a variable such as window . GUI code can be quite complicated with multiple elements so it is sensible to use a comment for each section. Setting the title , size and background colour of your window is optional but can be easily set up at the start of your code. The .geometry() command sets the size of the window. The first number is the width , and the second number is the height . The .configure() command can be used to set the background colour . For a full list of compatible colours, check here . import tkinter #Setting up the Window window = tkinter.Tk() window.title( "Graphical User Interface" ) window.geometry( "400x400" ) window.configure(background = "lightblue" ) import tkinter #Setting up the Window window = tkinter.Tk() window.title( "Example Number Two" ) window.geometry( "300x400" ) window.configure(background = "darkorchid3" ) Creating Elements Creating Elements: Labels, Entry Boxes, Buttons, Radio Buttons, Images, Message Boxes Labels label1 = tkinter.Label(window, text = "Hello there" ) label1 = tkinter.Label(window, text = "Hello there" , fg = "black" , bg = "lightblue" , font = ( "Arial" , 12)) Simple label with default formatting: Label with custom formatting: No elements will appear in your window until you write code to put them there. See the 'Displaying Elements' section further down. Entry (Text) Boxes Simple entry box with default formatting: entry1 = tkinter.Entry(window ) Entry boxes will appear blank , the 'Example Text' shown in the images has been typed in. Entry box with custom formatting: entry1 = tkinter.Entry(window, fg = "blue" , bg = "gray90" , width = 12, font = ( "Arial" ,12)) Buttons The command property of a button is a subroutine that will be called when the button is pressed . The subroutine must be written above the button creation code. def ButtonPress (): #Code here runs when the button is pressed button1 = tkinter.Button(window, text = "Click Me" , fg = "black" , bg = "gold2" , command = ButtonPress) Radio Buttons The Radiobutton element is a multiple-choice option button . A variable needs to be created to track which option has been selected, in this example it is ‘choice ’. Each radio button needs to be linked to the variable and given a unique value (e.g. 0, 1, 2). The radio button with the the value of 0 will be automatically selected when the window opens . Although not shown below, the .set() command can also be used to select a specific radio button , e.g. choice.set(2) . choice = tkinter.IntVar() radio1 = tkinter.Radiobutton(window, text = "Breakfast" , variable = choice, value = 0) radio2 = tkinter.Radiobutton(window, text = "Lunch" , variable = choice, value = 1) radio3 = tkinter.Radiobutton(window, text = "Dinner" , variable = choice, value = 2) Message Boxes You need to import messagebox from tkinter before you can use message boxes . You only need to do this once in your program and it sensible to have it at the very start after you import tkinter (and any other libraries). from tkinter import messagebox tkinter.messagebox.showinfo( "Information" , "Welcome to the program!" ) tkinter.messagebox.showerror( "Error" , "There is a problem with the program." ) if (tkinter.messagebox.askyesno( "Warning" , "Have you understood the instructions?" )) == True : tkinter.messagebox.showinfo( "Warning" , "Thank you for understanding." ) else : tkinter.messagebox.showinfo( "Warning" , "Please read the instructions again." ) Yes / No Message Box Clicking Yes (True ) Clicking No (False ) Images Tkinter supports the image file types .png and .gif . The image file must be saved in the same folder that the .py file is. Resize the image in separate image editing software such as Paint to a specific size . Tkinter does not support all image file types, such as .jpg. Use an application like Microsoft Paint to save an image with a different extension like .png. photo1 = tkinter.PhotoImage(file = "hamster.png" ) photoLabel1 = tkinter.Label(window, image = photo1) An image can be turned into a clickable button rather than a label. def ButtonPress (): #Code here runs when the button is pressed photo1 = tkinter.PhotoImage(file = "hamster.png" ) button1 = tkinter.Button(window, image = photo1, command = ButtonPress) photo1 = tkinter.PhotoImage(file = "hamster.png" ) window.iconphoto( True , photo1) The icon of the window can be changed to an image . Displaying Elements: Pack, Place and Grid Pack .pack() puts the element in the centre of the window, with the next packed element immediately below. window.mainloop() should always be your last line of code in every program, after you have packed, placed or gridded your elements. Displaying Elements labelAdd.pack() buttonAdd.pack() labelMinus.pack() buttonMinus.pack() window.mainloop() Place The .place() command allows an element to be placed in specific coordinates , using x (horizontal ) and y (vertical ) axes. labelAdd.place(x = 25, y = 15) buttonAdd.place(x = 12, y = 35) labelMinus.place(x = 90, y = 15) buttonMinus.place(x = 83, y = 35) window.mainloop() Grid The .grid() command is used to create a grid system to set the row and column . Remember Python starts counting at 0 . You can use padx and pady to add extra space (x is horizontal , y is vertical ). labelAdd.grid(row = 0, column = 0, padx = 10, pady = 5) buttonAdd.grid(row = 1, column = 0, padx = 10) labelMinus.grid(row = 0, column = 1, padx = 10, pady = 5) buttonMinus.grid(row = 1, column = 1, padx = 10) window.mainloop() Inputs & Outputs Inputs and Outputs .config to Change an Element .config() overwrites the property of an element. It can be used with elements such as labels and buttons to change how they appear. label1.config(text = "Warning!" ) The example below (not showing setup and packing) adds 1 to a total variable when the button is pressed . Config is used in two ways: to display the updated total and to change the background of the label to green. def AddOne (): global total total = total + 1 labelTotal.config(text = total, bg = "green" ) total = 0 buttonAdd = tkinter.Button(window, text = "Add" , command = AddOne) Below is a similar program in full that increases or decreases and displays a total when the buttons are pressed . #Setup import tkinter window = tkinter.Tk() total = 0 #Button Presses def AddOne (): global total total = total + 1 labelTotal.config(text = total) def MinusOne (): global total total = total - 1 labelTotal.config(text = total) #Create Elements labelTotal = tkinter.Label(window, text = total, font = ( "Arial" ,14)) buttonAdd = tkinter.Button(window, text = "+" , width = 6, bg = "green" , command = AddOne) buttonMinus = tkinter.Button(window, text = "-" , width = 6, bg = "red" , command = MinusOne) #Display Elements buttonAdd.pack() buttonMinus.pack() labelTotal.pack() window.mainloop() .get to Input a Value .get() returns the value of an element such as an entry box , label or the choice variable if using radio buttons . The value of the element should be stored in a variable so it can be used elsewhere, for example: name = entryName.get() number = int (entryNumber.get()) Use int when getting a value that is an integer : The full program example below checks that the values typed into the username and password entry boxes are correct . Error Messages #Setup import tkinter from tkinter import messagebox window = tkinter.Tk() window.title( "Login" ) #Button Presses def CheckDetails (): username = entryUsername.get() password = entryPassword.get() if username == "Bob Bobson" and password == "cabbage123" : tkinter.messagebox.showinfo( "Success" , "Welcome " + username) else : tkinter.messagebox.showerror( "Invalid ", "Those details are incorrect." ) #Create Elements labelUsername = tkinter.Label(window, text = "Username:" ) labelPassword = tkinter.Label(window, text = "Password" ) entryUsername = tkinter.Entry(window) entryPassword = tkinter.Entry(window) buttonLogin = tkinter.Button(window, text = "Login" , command = CheckDetails) #Display Elements labelUsername.grid(row = 0, column = 0) entryUsername.grid(row = 0, column = 1) labelPassword.grid(row = 1, column = 0) entryPassword.grid(row = 1, column = 1) buttonLogin.grid(row = 2, column = 0) window.mainloop() .bind for Key Presses (& Close Window) .get() will run a specific function when a certain key is pressed. The name of the key must be surrounded by < > brackets and speechmarks . Any associated subroutine of a key bind will need a parameter : event has been chosen and set to None . The code below closes the window using the .destroy() command when the Esc key is pressed. def Close (event = None ): window.destroy() window.bind( "" , Close) The code below will activate the button (and display a message box) by clicking on it but also by pressing the Enter ( Return ) key . def ButtonPress (event = None ): tkinter.messagebox.showinfo( "Success" , "The button was activated" ) button1 = tkinter.Button(window, text = "Press Me" , command = ButtonPress) window.bind( "" , ButtonPress) GUI Tasks GUI Programs to Make Making a program using a GUI can be overwhelming and you must decompose the problem - take it step by step : Import tkinter and create the window (set the title, size and background colour). Create the elements you will need such as labels , buttons and entry boxes . Put the components in the window using pack , place or grid . Write the subroutines for any button presses . These are written at the top of the program after the window setup. Consider your variables - do any need to be set at the start ? Have you made them global if they’re needed within a subroutine ? Put window.mainloop() as the final line of code, only have it once. Use #comments in your code to break up the different sections, the key four sections are shown below. #Setup #Button Presses #Create Elements #Display Elements GUI Task 1 (Random Number Generator ) Generate a random number between 1 and 100 when the button is pressed and display it in a label. Extension idea: Use entry boxes to allow the user to manually input the minimum and maximum value. Example solution: GUI Task 2 (Currency Exchange ) Enter a decimal value and convert it from British pounds to American dollars. You can search for the current exchange rate. Extension idea: Show the conversion rate for other currencies such as Euros and Japanese Yen. Example solution: GUI Task 3 (Random Quote Generator ) Create a list of quotes and use the choice command from the random library to select one to be displayed in a label when the button is clicked. Extension idea: Have a separate text box and button to add more quotes to the list. Example solution: GUI Task 4 (Colour Changer ) When the button is clicked change the background colour of the button with .config to the RGB colour code in the entry box. This should be # followed by 6 hexadecimal values (0-9, A-F). Extension idea: Have an error pop up in a message box if the colour code is incorrect - it must be exactly 7 characters long and start with a hashtag. Example solutions: GUI Task 5 (Class Captain Votes ) Use radio buttons to vote for different candidates in a class vote. Use an if statement when the button is pressed to check which radio button is selected using .get() and the variable you've assigned to the radio buttons ('choice' if you've followed the code in the radio buttons section on this page). Use .config to overwrite a label's value. Remember any variables you want to use in subroutines must be globalised. Extension idea: Stop the count after a certain number - e.g. 30 votes recorded. Example solution: ⬅ Section 10 Practice Tasks 12 - Error Handling ➡

  • 2.3.1a - Object Oriented Programming | OCR A-Level | CSNewbs

    Based on the OCR Computer Science A-Level 2015 specification. Exam Board: OCR 3.1a - Algorithm Design Specification: A-Level 2015 An instruction set is a list of all the instructions that a CPU can process as part of the FDE cycle . CPUs can have different sets of instructions that they can perform based on their function. The two most common instruction sets are the simpler RISC (Reduced Instruction Set Computer ) and more complicated CISC (Complex Instruction Set Computer ). Instruction Sets This page is still being updated. Graphical Processing Unit What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Multicore & Parallel Systems What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Multicore & Parallel Systems What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Q uesto's Q uestions 3.1a - Algorithm Design: 1. What is cache memory ? [ 2 ] 2.2b - Object Oriented Programming Theory Topics 3.1b - Big O Notation

  • HTML Guide 4 - Hyperlinks | CSNewbs

    Learn how to link to other websites by using the anchor tag. 4. Hyperlinks HTML Guide Watch on YouTube: A hyperlink is a link to another web page . In this section, you will link your page to a real website, like Wikipedia. Hyperlinks require the anchor tags and Copy a URL Firstly you need to copy the full web address of the web page that you would like to link your page to. Choose an appropriate web page that relates to your chosen topic. Create the Anchor Tag 4. Close the start of the tag . 1. Open the start of the tag . 2. Type href (stands for hypertext reference ). 3. Paste the URL inside speech marks . 5. Type the text you want the user to click on . 6. Time to close the tag . When you save your webpage and run it in a browser you will be able to click highlighted text to open the website you have chosen. Add at least three different hyperlinks to your webpage. Try to add the 2nd & 3rd links without looking at this page - practise makes perfect. Add a Hyperlink within a Sentence You can also create an anchor tag within a sentence. Hyperlinks are important to link webpages together. Next is time for adding pictures! Either change one of your previous hyperlinks to be in the middle of a sentence or create a new one. 3. Text Tags HTML Guide 5. Images

  • HTML Guide 9 - Colours & Fonts | CSNewbs

    Learn how to use the style tags in an HTML document to edit the background colour and font text and colour. 9. Style (Colours & Fonts) HTML Guide Watch on YouTube: Before you add any colours or font styles, you need to add tags. The style tags must be written within your head of your HTML document! Add them below your title tags: Add the

  • 3.3b - Protocols & TCP-IP Stack | OCR A-Level | CSNewbs

    Based on the OCR Computer Science A-Level 2015 specification. Exam Board: OCR 3.3b - Protocols & TCP-IP Stack Specification: A-Level 2015 An instruction set is a list of all the instructions that a CPU can process as part of the FDE cycle . CPUs can have different sets of instructions that they can perform based on their function. The two most common instruction sets are the simpler RISC (Reduced Instruction Set Computer ) and more complicated CISC (Complex Instruction Set Computer ). Instruction Sets This page is still being updated. Graphical Processing Unit What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Multicore & Parallel Systems What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Multicore & Parallel Systems What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Q uesto's Q uestions 3.3b - Protocols & TCP-IP Stack: 1. What is cache memory ? [ 2 ] 3.3a - Network Characteristics Theory Topics 3.3c - Hardware & DNS

  • 2.3 - Software Development Methodologies | OCR A-Level | CSNewbs

    Based on the OCR Computer Science A-Level 2015 specification. Exam Board: OCR 2.3: Software Development Methodologies Specification: A-Level 2015 An instruction set is a list of all the instructions that a CPU can process as part of the FDE cycle . CPUs can have different sets of instructions that they can perform based on their function. The two most common instruction sets are the simpler RISC (Reduced Instruction Set Computer ) and more complicated CISC (Complex Instruction Set Computer ). Instruction Sets This page is still being updated. Graphical Processing Unit What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Multicore & Parallel Systems What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Multicore & Parallel Systems What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Q uesto's Q uestions 2.3 - Software Development Methodologies: 1. What is cache memory ? [ 2 ] 2.2b - Translators & Compilation Theory Topics 2.4a - Programming & Pseudocode

  • Python | Section 10 Practice Tasks | CSNewbs

    Test your understanding of working with files in Python, including reading, searching, writing and editing. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. Python - Section 10 Practice Tasks Task One Create a file in Python called DaysOfTheWeek.txt. Write the days of the week into the file in a single print line but put each day on a new line. Check the file to see if it has worked. Example solution: Task Two Create a file called Colours.txt. Use a for loop to ask the user to enter 8 different colours. Write each colour onto the same line, with a space between the colours. Close the file and open it again in read mode and print it. Example solution: Task Three Create a file named "Holiday.txt". Ask the user to enter the family name, destination and and number of passengers. Print each family's details on their own line. Bonus: Edit this program to add a search feature to look for the family name. Example solution: Task Four Use the holiday file from task three above. You are going to change the destination. Ask the user to enter a family name and then a new destination. Update the destination with the new value. Check the file to ensure the destination has been updated successfully. Use section 10c to help you with this task. Example solution: ⬅ 10c - Remove & Edit Lines 11 - Graphical User Interface ➡

  • 1.3b - Memory & Storage | OCR A-Level | CSNewbs

    Based on the 2015 OCR Computer Science A-Level specification. Exam Board: OCR 1.3b: Memory & Storage Specification: A-Level 2015 An instruction set is a list of all the instructions that a CPU can process as part of the FDE cycle . CPUs can have different sets of instructions that they can perform based on their function. The two most common instruction sets are the simpler RISC (Reduced Instruction Set Computer ) and more complicated CISC (Complex Instruction Set Computer ). Instruction Sets This page is still being updated. Graphical Processing Unit What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Multicore & Parallel Systems What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Multicore & Parallel Systems What is cache memory? Cache memory is temporary storage for frequently accessed data . Cache memory is very quick to access because it is closer to the CPU than other types of memory like RAM . Q uesto's Q uestions 1.3b - Memory & Storage: 1. What is cache memory ? [ 2 ] 1.3a - Input & Output Theory Topics 2.1 - Operating Systems

  • 5.1 - Data Structures - Eduqas GCSE (2020 Spec) | CSNewbs

    Learn about different data structures such as arrays, lists and records. Also, the difference between static and dynamic data structures and how to design files. Based on the 2020 Eduqas (WJEC) GCSE specification. 5.1: Data Structures & File Design Exam Board: Eduqas / WJEC Specification: 2020 + What is a Data Structure? A data structure is a way of efficiently organising data . There are two general forms of data structures: Static Data Structures The size of a static data structure cannot change e.g. if a data structure has 20 elements, no additional elements can be added or removed. The values of the data elements can be changed, but memory size is fixed when allocated at compile time. Because a static data structure holds a certain number of data elements they are easier to program because the size of the structure and the number of elements never change. An array is an example of a static data structure. Examples: A static data structure could be an array of teams in the Premier League. The data elements will change each year when teams are relegated and promoted but there will always be 20 teams. Dynamic Data Structures The size of a dynamic data structure can change as the program is being run , it is possible to add or remove data elements. Dynamic data structures make the most efficient use of memory but are more difficult to program , as you have to check the size of the data structure and the location of the data items each time you use the data. A list is an example of a dynamic data structure. A dynamic data structure could be a list of all teams in the Premier League that won their last match. Data elements (teams) will be added or removed across the season. Types of Data Structures List A list is a dynamic data structure that has the data elements stored in the order they were originally added to memory . Every data structure starts at 0, not 1 . Lists store data elements in the order they were added, so the first doctor is 0 and the most recent doctor is 12. An example list of the main Doctor Who actors Array An array is a static data structure that can hold a fixed number of data elements . Each data element must be of the same data type i.e. real, integer, string. The elements in an array are identified by a number that indicates their position in the array. This number is known as the index. The first element in an array always has an index of 0 . You should know how to write pseudo code that manipulates arrays to traverse, add, remove and search data. The following steps uses Python as an example. Traversing an Array To traverse (' move through ') an array a for loop can be used to display each data element in order. 'Inserting' a value In an array the size is fixed so you cannot insert new values, but you can change the value of elements that already exist. Overwriting the fourth element (Daphne) with a new value (Laura) will change it from Daphne to Laura. Example code for traversing: Example code for inserting: Output: Output: 'Deleting' a value In an array the size is fixed so you cannot delete values, but you can overwrite them as blank . Overwriting the second element (Shaggy) with a blank space makes it appear deleted. Example code for deleting: Output: Searching an Array For large arrays a for loop is needed to search through each element for a specific value . This example checks each name to see if it is equal to Velma. Example code for searching: Output: Two-Dimensional Array Often the data we want to process comes in the form of a table . The data in a two dimensional array must still all be of the same data type , but can have multiple rows and columns . The two-dimensional array to the right shows the characters from Scooby Doo along with their associated colour and their species. Each value in the array is represented by an index still, but now the index has two values . For example [3] [0] is 'Daphne'. We measure row first , then column . Searching a two-dimensional array: To print a specific data element you can just use the index number like Daphne above. To search for a specific value you will need two for loops, one for the row and another for the values of each row. The example to the right is looking for the value of 'Velma' and when it is round it prints the associated data from the whole row. Example code for printing: Output: Example code for searching: Output: Records Unlike arrays, records can store data of different data types . Each record is made up of information about one person or thing. Each piece of information in the record is called a field (each row name). Records should have a key field - this is unique data that identifies each record . For example Student ID is a good key field for a record on students as no two students can have the same Student ID. Data files are made up of records with the same structure. It would be most efficient for the fields in a record to be stored next to each other so that the data can be read into the record data structure in memory for processing by the CPU. In an exam you may be asked to state and design a data structure for a given scenario. If the data structure can hold values of the same data type you should draw an array , usually a 2D array for multiple rows and columns. Remember that a record is required to store values of different data types . Example questions: "A video gamer has recorded their three lap times in four Mario Kart courses." " State and design the most suitable data structure for this data." A two-dimensional array is most suitable because only one data type ( real ) is stored. "A vet surgery stores data on all dogs and cats including the animal's name, age (in years), weight (in kg) and whether or not it has been vaccinated." " State and design the most suitable data structure for this data for four animals ." A record is most suitable because the data structure requires different data types . Q uesto's Q uestions 5.1 - Data Structures: 1. Give two differences between static and dynamic data structures . [ 4 ] 2. Describe the differences between a list , array and record . [ 3 ] 3. A one-dimensional array looks like this: TigerBreeds("Sumatran","Indian","Malayan,"Amur") Write the code to: a. Print the element with the index of 3. [ 2 ] b. Change Indian to South China. [ 2 ] c. Remove the Amur element. [ 2 ] d. Search through the array for 'Malayan'. [ 2 ] 4. State and design the most suitable data structure for these scenarios: a. For each book in a bookshop, the staff need to record the title, author, number of pages and whether or not it is a signed copy. Include data for three books. [ 3 ] b. Four dieters are recording how many kilograms they have lost each month for 5 months. [ 4 ] 5. Design a file that stores the first initial, surname, age and hair colour of each member of a family. [ 8 ] Designing Data Structures Data is stored in files when it needs to be kept after the program has stopped running . To learn how to write code for file handling (e.g. opening, writing to, reading from and closing files) in Python click here . Designing a file requires more than just the field name (e.g. Name) and data values (e.g. Rebecca). The data type (e.g. string) and any validation checks (e.g. format check) should also be considered. Below is an example file design for a bakery. Designing Files 4.8 Compression Theory Topics 6.1 - Operating Systems

  • | CSNewbs

    Preparation is the key to success. I won't say "Good Luck", because luck won't make you pass an exam. Focus and effort will. Thanks sir, now let me use your awesome site.

© CSNewbs 2025

The written, video and visual content of CSNewbs is protected by copyright. © 2025
bottom of page