Search CSNewbs
304 results found with an empty search
- Python | 10a - Open & Write to Files | CSNewbs
Learn how to create, open and write to files in Python. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. Python 10a - Open & Write To Files Creating and Opening Files The "a" opens the file in append mode which will add new data to the end of the file. The open command is used to open files but it is also used to create new files . 'file' is just a variable and can be more relevant such as customer_file or whatever your file will be storing. Python looks in the same folder as your .py file and checks to see if Customers.txt already exists. If it doesn't exist, it will create the file . The .txt extension will create a Notepad file. You can use alternatives such as .text or .docs. Writing to a File In the example below I ask the user to input a name which is written to the Names.txt file. The .write command writes the contents of the brackets to the file . You must close the file with the .close() command or the contents will not be saved . The .write command can be adapted depending on how you want the file to appear: Your text file won't update while it is open . Close it and open it again to see any changes . If you make any mistakes, just edit the file by hand and save it again. Practice Task 1 Create a new file called MyFriends.txt Ask the user to enter 5 names. Write the 5 names into a file. Place each name on a separate line. Check the file to see if the names have been entered. Example solution: Writing Multiple Lines to a File Files are often used to store data about multiple people . The program below asks for a customer's name, appointment date and VIP status then saves this information into a file. The plus symbol is used to write information for a single customer on the same line . This is beneficial if you want to search for a customer later. Practice Task 2 Create a new file called ALevels.txt Ask the user to enter a student's name and their three A-Level subjects. Write each student's information on the same line. Enter at least three different students and check your file to see it has worked. Example solution: ⬅ Section 9 Practice Tasks 10b - Read & Search Files ➡
- 1.7 & 1.8 - Internet Pros & Cons | Unit 2 | OCR Cambridge Technicals | CSNewbs
Learn about the advantages and disadvantages to individuals and organisations when using the internet. Based on the 2016 OCR Cambridge Technicals Level 3 IT specification for Unit 2 (Global Information). 1.7 & 1.8 - Internet Pros & Cons Exam Board: OCR Specification: 2016 - Unit 2 The internet has become easier and cheaper to access since the mid 1990s and today it is almost taken for granted. The rise of the internet, and the services it provides, has lead to advantages and disadvantages for both individuals and organisations . Advantages for Individuals Increased speed of personal communication Allows for instant messaging, emails and video chats across the world. Easy access to information The internet has free resources such as CSNewbs and Wikipedia, plus academic journals for research & study. 24/7 access to services Shopping, browsing and banking can be completed when convenient for the user. Social interaction with others Social media, discussion forums and online games provide entertainment and social interaction. Disadvantages for Individuals Potential for identity theft Uploading personal data and storing sensitive information risks hackers obtaining and utilising it. Cost of connection & services Internet service providers (ISPs) charge a monthly fee and equipment like a router needs installation. Cyberbullying & trolling The abuse of others on social media is possible. Anonymisation makes it harder to catch offenders. Spreading misinformation 'Fake news' or biased information can be easily spread on social media and lead to incorrect assumptions. Source of distraction Staff and students may neglect their work and study for entertainment or social media. Advantages for Organisations Share data quickly globally Files and information can be sent instantly to locations across the world. Cloud storage can store data. Online services always available E-commerce businesses can operate 24/7 globally, permit users to browse and accept payments. Easy internal communication Staff can use emails, video calls or instant messages to communicate. Open up the workplace Staff can work from home, on the commute to/from work and outside of the office. Disadvantages for Organisations Malicious attacks & threats Websites can be hacked / taken offline with DDoS attacks. Data can be stolen or corrupted. Cost of maintaining services Most companies require an IT department to oversee device installation and maintenance. Reputation and controversies Companies that leak data will damage their reputations. Social media posts could backfire. Q uesto's Q uestions 1.7 - Internet Pros & Cons: 1. List 5 points for the following categories (you may need to include researched / your own points for some): a. Advantages of the internet for individuals [5 ] b. Disadvantages of the internet for individuals [5 ] c. Advantages of the internet for organisations [5 ] d. Disadvantages of the internet for organisations [5 ] 1.6 - Information Formats Topic List 2.1 - Information Styles
- 1.3 - Primary Storage - Eduqas GCSE (2020 spec) | CSNewbs
Learn about the five types of primary storage - RAM, ROM, cache, flash and virtual memory. Based on the 2020 Eduqas (WJEC) GCSE specification. 1.3: Primary Storage (Memory) Exam Board: Eduqas / WJEC Specification: 2020 + Storage in a computer system is split into two categories. Primary Storage: Very quick to access because it is attached to the motherboard . Typically smaller in storage size . Sometimes called ‘main memory’ . Secondary Storage: Slower to access because it is not directly embedded on the motherboard . Typically larger in storage size . Sometimes called ‘backing storage’ . Storage is also split into two types - volatile and non-volatile . Volatile storage is temporary - data is lost whenever the power is turned off . Example: RAM Non-volatile storage saves the data even when not being powered . Data can be stored long-term and accessed when the computer is switched on . Example: ROM Types of Primary Storage (Memory) Random Access Memory (RAM) RAM is volatile (temporary) storage that stores all programs that are currently running . RAM also stores parts of the operating system to be accessed by the CPU. RAM is made up of a large number of storage locations, each can be identified by a unique address . Read-Only Memory (ROM) Cache Memory ROM is non-volatile storage that cannot be changed . ROM stores the boot program / BIOS for when the computer is switched on. The BIOS then loads up the operating system to take over managing the computer. Cache memory is volatile (temporary) storage that stores data that is frequently accessed . It is very quick to access because it is closer to the CPU than other types of memory like RAM. The three levels of cache memory are explained in more detail in 1.5 . RAM ( R andom A ccess M emory) ROM ( R ead O nly M emory) Cache Memory Flash Memory Flash memory is editable so it can be read and written to . It is also non-volatile so it can be used for long-term data storage even when the system is not powered on. Flash memory is also used for secondary storage devices like USB sticks and solid-state drives - see 1.4 . Virtual Memory When a computer system is running slowly and RAM is near full capacity , the operating system will convert storage space on the drive into temporary memory . This virtual memory slows the system down because it takes longer to access the drive than it does to manage RAM. Transferring data between RAM and virtual memory is called paging . Q uesto's Q uestions 1.3 - Primary Storage (Memory): 1. Describe the differences between primary and secondary storage . This could be done in a table with the column headings 'access speed' , 'storage size' and 'also known as' . [ 6 ] 2. Explain the difference between volatile and non-volatile storage . State an example of both types. [ 4 ] 3. For each type of memory below, describe it and state what information is stored within it: a . Random Access Memory (RAM) [3 ] b. Read-Only Memory (ROM) [ 3 ] c. Cache memory [ 3 ] d. Flash memory [ 3 ] e. Virtual memory [ 3 ] 1.2 - FDE Cycle 1.4 - Secondary Storage Theory Topics
- 4.3 - Boolean Algebra | OCR A-Level | CSNewbs
Learn about boolean logic and expressions using NOT, AND OR and XOR, Karnaugh maps, Boolean algebra rules including De Morgan’s Laws, distribution, association, commutation and double negation, logic gate diagrams, truth tables, D-type flip flops, half adders and full adders. Based on the OCR H446 Computer Science A-Level specification. Exam Board: OCR A-Level Specification: Computer Science H446 4.3 - Boolean Algebra Watch on YouTube : Boolean Logic (NOT, AND, OR, XOR) Karnaugh maps Boolean algebra rules Logic gate diagrams Truth tables D-type flip flops Half & full adders This topic explores how the logical operations NOT , AND , OR and XOR are used to process binary data and control digital systems . It also looks at how to simplify and represent logic using Karnaugh maps , Boolean algebra rules , logic gate diagrams and truth tables . Boolean Logic Boolean logic is a form of algebra in which all values are either True (1 ) or False (0 ). It’s used in computing and digital circuits to make decisions and control the flow of programs . NOT (negation ) (¬ ) reverses the input value - 1 becomes 0 and 0 becomes 1 . AND (conjunction ) (∧ ) outputs 1 only if both inputs are 1 (e.g. 1 AND 1 = 1 , otherwise 0 ). OR (disjunction ) (v ) outputs 1 if at least one input is 1 (e.g. 1 OR 0 = 1 ). XOR (exclusive disjunction ) (v ) outputs 1 only if one input is 1 but not both (e.g. 1 XOR 1 = 0 , 1 XOR 0 = 1 ). YouTube video uploading soon Karnaugh Maps A Karnaugh map is a visual method used to simplify Boolean expressions and make logic circuits more efficient . It organises all possible input combinations into a grid , where adjacent cells differ by only one bit (following Gray code order ). By grouping together 1s (representing True outputs ) in powers of two (1 , 2 , 4 or 8 cells ), you can identify and remove redundant terms in a Boolean expression . The simplified result reduces the number of logic gates needed in a circuit, making it faster and easier to build . YouTube video uploading soon Boolean Algebra Rules Boolean algebra rules are used to simplify Boolean expressions . De Morgan’s Laws show how to distribute negation across AND and OR operations: ¬(A AND B) = (¬A OR ¬B) and ¬(A OR B) = (¬A AND ¬B) . Distributive Law allows expressions to be expanded or factored , e.g., A AND (B OR C) = (A AND B) OR (A AND C) and vice versa for OR over AND. Associative Law means the grouping of terms doesn’t affect the result . (A AND B) AND C = A AND (B AND C) and (A OR B) OR C = A OR (B OR C) . Commutative Law means the order of terms doesn’t matter in Boolean operations, e.g., A AND B = B AND A and A OR B = B OR A . With Double Negation , two NOTs cancel each other out , returning the original value , e.g., ¬¬A = A . YouTube video uploading soon Logic Gate Diagrams Logic gate diagrams are visual representations of Boolean expressions or digital circuits , showing how data flows through logic gates to produce an output . Each gate performs a basic logical operation (such as NOT , AND , OR or XOR ) and is represented by a distinct symbol . NOT AND OR XOR YouTube video uploading soon Truth Tables A truth table is used to show all possible input combinations for a logic circuit or Boolean expression , along with the resulting output for each combination . Each row in the table represents a unique set of input values (usually 0 for False and 1 for True ). The final column shows the output produced by applying the logical operations to those inputs . The number of rows in a truth table doubles with each additional input , e.g. 4 rows for 2 inputs and 8 rows for 3 inputs . YouTube video uploading soon D-Type Flip Flops A D-type flip-flop i s a sequential logic circuit that stores a single bit of data - either 0 or 1 . It has two inputs , D (data ) and CLK (clock ), and two outputs , Q and ¬Q . When a clock pulse occurs , the flip-flop copies the value of D to the Q output , and that value is held (stored ) until the next clock pulse . This makes D-type flip-flops useful for memory storage , registers and data synchronisation . Essentially, they act as a 1-bit memory cell , storing the last value of D whenever the clock signal triggers . YouTube video uploading soon Half Adders & Full Adders A half adder is a logic circuit with two inputs (A and B ) that are added to produce two outputs - S (sum ), the result of A XOR B - and C (carry ), the result of A AND B . Half adders can only add two bits and cannot handle an input carry from a previous addition . A full adder is an extension of a half adder with three inputs : A , B , and C in (a carry-in from a previous calculation ). It produces two outputs : S (sum ) (A XOR B XOR Cin ) and C out (carry out ) ((A AND B) OR (B AND Cin) OR (A AND Cin) ). Full adders can be linked together to perform multi-bit binary addition in arithmetic circuits. YouTube video uploading soon This page is under active development. Check here for the latest progress update. Q uesto's K ey T erms Boolean Logic: NOT, AND, OR, XOR, Karnaugh maps, logic gate diagrams, truth tables Boolean Algebra Rules: De Morgan’s Laws, distribution, association, commutation, double negation D-Type Flip Flops: data, clock, Q, NOT Q Adders: half adder, full adder D id Y ou K now? The word ' Boolean ' is always spelt with a capital B because it is named after George Boole , a 19th-century English mathematician . His work has become the foundation of all modern digital electronics and computing . 4.2 - Data Structures A-Level Topics 5.1 - Computing Legislation
- Python | 8c - Dictionaries | CSNewbs
Learn how to create and use dictionaries in Python. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. top Python 8C - Dictionaries Creating a Dictionary Dictionaries are used in Python to link items of data together . The example on this page uses a footballer dictionary which links a player with a team they played for. To define a dictionary, use curly brackets { } and separate linked data with a colon . A dictionary can be written on one line but the method below makes it easier to read: Printing Data from a Dictionary The first part of the linked data in a dictionary is called the key (e.g. each footballer in my example above). The second part of the linked data in a dictionary is called the value (e.g. each team). Example: key : value "Harry Kane" : "Tottenham Hotspur" A for loop can be used to cycle through each set of keys and values in the dictionary: Practice Task 1 a) Create a dictionary of your teachers and the subject they teach. b) Print their name and the subject they teach on each line. Example solution: Adding and Removing Data from a Dictionary Data can be added to a dictionary by stating the new key and value . You must use square brackets - [ ] The new data will be added to the end of the dictionary. You can print the whole dictionary to see any changes - e.g. print(playerdictionary) Data can be removed from a dictionary by stating the new key to remove in a pop command. You can print the whole dictionary to see any changes - e.g. print(playerdictionary) The whole dictionary can be cleared (reset to blank) using the clear command. Practice Task 2 a) Ask the user to enter a new teacher and their subject. b) Ask the user to remove a teacher. c) Print the list of teachers and check the new teacher has been added and the other one removed. Example solution: Searching Through a Dictionary An if statement can be used to check if a specific key is in a dictionary. If the key is in the dictionary then a message can be displayed using the key and the value . Otherwise, an else statement can output an appropriate response. To search for a value in a dictionary a for loop should be used to cycle through each key . If the value of each key matches the value that is being searched for then it will be printed. Practice Task 3 a) Create a search that allows a user to enter a teacher's name and prints the subject that they teach. b) Include an else statement to print a response if a teacher is not in the dictionary. Example solution: Changing Data & Copying a Dictionary The way to change values is similar to adding new data. The first input below is to determine the key and the second input determines the new value to be changed to. The copy command is used to make a duplicate of a dictionary . Practice Task 4 a) Create a copy of your teacher dictionary. b) Allow the user to enter a teacher and a new subject that they teach. c) Print the copy of the dictionary with the new values. Example solution: Using a Dictionary to Make a Game The code below is used to make a puzzle game where the user has to type in a footballer and the team they played for. I have added comments to explain the different parts of the code. A separate list has been created at the start to store the names of keys (players) that been correctly guessed . A while loop is used to constantly ask the user for players and teams. When they have guessed all 10 players (and the correct list reaches 10 ) the loop breaks and the game end. Instead of a further practice task here, Task 6 of the Section 8 Practice tasks page challenges you to make a similar game using a dictionary. ⬅ 8b - 2D Lists Section 8 Practice Tasks ➡
- Scratch Maze Game | CSNewbs
This walkthrough will show you how to create a maze game in Scratch . It is split into the following sections: Creating the First Level Choosing the Main Character Animating & Moving the Main Character Back to the Start Adding Score & Time Making Enemies Adding More Levels Extensions Use the links to move between sections easily! 1. Creating the First Level The very first thing to do is to create the level in which our character will move around in! We are going to draw a background from scratch which our hero will run around in to get to the end. Important parts of the pictures are highlighted in yellow ! 1. Select the blank Stage button in the button left to edit the background. Drawing the Background Challenge Task Anchor 1 2. Press on the Backdrops tab. This will show Scratch’s own paint editor on the right. 3. Use the line tool to create straight maze lines on the background. Use the slider at the bottom to increase the width of the line. Remember this is only the first level so don’t make it too difficult. 4. Create a start zone and an end zone with the rectangle tool and then fill them in with the fill bucket tool . You can also change the main background colour using the fill bucket tool. Remember to choose an appropriate level name in the text box at the top. Level Name Rectangle Tool Fill Bucket Tool Make your game more exciting by creating themed levels , like this park background. Other ideas might include a classroom, library or car park. Try switching up the start and end zones by using the circle tool or the line tool and the fill bucket . Come back to this challenge when you are ready to make more levels! 2. Choosing the Main Character Now that you have your first level designed we can make our hero character who is going to navigate the maze and try to get to the end. Picking the main character Anchor 2 1. A character is called a sprite . We will choose a sprite from Scratch’s sprite library . Click on the fairy icon to open the sprite menu. 2. I have selected the Animals category on the left menu. I have chosen the Penguin sprite but choose whichever character you want. 3. Press the Costumes tab and check that your chosen sprite has at least two costumes . We will use these to create animation in the next section to make it look like the sprite is moving. 4. Now that we don’t need the cat anymore we can delete him by right-clicking on his icon and selecting delete . Shrink the Main Character down to size Shrink Tool 5. The sprite is too big for the level background and you will need to shrink them down . Click on the shrink button at the top of the program and then click on the sprite in the paint area to shrink them down. Remember how many times you clicked the sprite to shrink it. You will need to shrink both costumes the same number of times . Here I have shrunk my penguin by 17 clicks when I selected the shrink tool. You can compare the size of your costumes by looking at the image size beneath the icon (e.g. 40 x 53). Picture Size 6. You need to make sure that your sprite is in the centre of the grid otherwise it might cause trouble later when you try to move them. Click on the costume centre button in the top right (it looks like a crosshair ) and drag your sprite into the middle if it is not. Make sure that both costumes are in the centre . Also, give your costumes appropriate names , I have named mine Mr. Penguin 1 and Mr. Penguin 2. Costume Name Costume Centre 3. Animate & Move the Main Character Adding Animation Anchor 3 1. Click on your sprite icon in the bottom left and then on the Scripts tab in the top centre. We will begin using the script blocks and we need to start in the Events category with: ...so drag it over to the script area. This script will run all the blocks that we place beneath it, when the flag is pressed to start the game. 1. 2. You can only add animation if the sprite you chose has at least two different costumes! 2. The second block we need is: ...in the Control category. Every block that we put inside the forever loop block will repeat again and again . We want our character to switch between their costumes infinitely to make it look like they are always walking, which is why we use the forever loop. 3. Click on the Looks category and drag two... ...inside of your forever loop . Use the drop down list (small black triangle on the costume block ) to make one block switch to your first costume and the other block switch to your second costume. 4. In the Control category, drag over two blocks and place one after each of your ‘switch costume to ‘ blocks. 1 second is too long to wait so click on the 1 and change both to 0.5 instead (this is half a second). If you’ve got the code correct so far, when you press the green flag your character should be animated! Moving the Main Character 1. In the Events category drag a into the script area. Change the button from space to ‘up arrow ’ (or any key you like) It is also popular for computer games to use the w key to move up. 2. Click on the Motion category and move over two blocks: and Change the angle of direction from 90 (which is a right turn) to 0 (which is an upwards turn). Now you have just created code to make your character move upwards by ten steps when you press the up arrow! Once you have dragged the blocks when the up arrow is pressed, you can work out how to make your character move down, left and right ALL BY YOURSELF. Add this code in now, before you move on . Rotate the Main Character If you press the green arrow and move your character around you might notice that it doesn't rotate when it moves. Click on the i in the top left of your sprite icon in the bottom left. There are three types of rotation to choose from. Select your preferred style by clicking on one of the three symbols. Full Rotation will turn your sprite up, down, left and right. Horizontal Rotation will only turn your sprite left and right. No Rotation will not turn your sprite at all. it will always appear in the same direction. Anchor 4 4. Back to the Start Starting in the right place We always want the main sprite to start in the green zone when the green flag is pressed to start the game. First drag your sprite to the green zone . Then go to the Motion category and drag over: ...and connect it directly underneath the block you dragged over earlier. Once you’ve added that line of code, click the green flag to make sure that the sprite starts where you want it to . If it doesn’t, then you can change the x (horizontal) and y (vertical) co-ordinates by clicking on the white boxes and changing the values. Back to the start if touching the walls 1. Drag over and connect together the two blocks below: 2. Drag over the two blocks below, put the blue one inside the other and then put them both inside the forever loop : 3. Change the co-ordinates in the blue block you just added so that it matches the same co-ordinates as the block to make the sprite start at the green zone . 4. Now to add the wall detection code! In the Sensing section, drag this block over... ...and put it inside the top of the ‘if then‘ block . Make sure that you put it between the 'if' and 'then' and not underneath. 5. Click once on the box in the ‘touching colour ‘ block and then click the wall or obstacle you want the player to avoid, Now is a good idea to play your game and make sure you can get to the end without being teleported back to the start. If your game is impossible you will need to edit the background – click on the stage icon in the bottom left then the Backdrops tab and edit the walls. Anchor 5 5. Adding Time & Score Recording the Time 1. Click on the Stage icon in the bottom left, we will create new code in the Scripts tab of the stage. DO NOT click the character sprite! Click on the Data category and choose Make a Variable . A variable is something that can change . Call your new variable Time . Adding a Score - The Number of Restarts 2. From the Events category drag: ...then look in the Data category and connect this underneath: ...but it should say Time instead of 'variable'. This code makes the time start at 0 when the game begins. 3. Now we need a loop that increases our variable called Time by 1 every second. First drag over a forever loop : Then place inside of it two blocks: Make sure it says Time instead of variable. Now press the green flag to see the timer go up. 1. In the Data section click on Make a Variable and give it an appropriate name like Restarts . This variable will count how many times we have touched a wall and had to start again. 2. Firstly, go back to the Scripts area for your character – click on the sprite of your main character in the bottom left then the Scripts tab. You need to add two blocks from the Data category: Change variable to Restarts and place it directly underneath the flag. Change variable to Restarts again and place this code directly after the 'go to ' block inside the loop. Now whenever you touch the wall you restart and it records it in the variable called Restarts. 6. Making Enemies Anchor 6 1. Select the fairy icon in the New sprite section to open the Scratch sprite library. 2. From the sprite library choose your enemy . I have selected the polar bear because it fits with my penguin. 3. Select the shrink tool at the top of the program and click on the enemy . Then drag them to where you want them to start . 4. Click on the sprite icon of your enemy then select the Scripts tab. Drag and connect two blocks: 5. From the Control category grab a: ...and place it after the ‘go to ‘ block. Now we will make our enemy glide from his start position to somewhere on our level again and again. Move the enemy to where you want it to go to then add: ...inside the forever loop. Drag another ‘glide ‘ block and place it underneath but change those co-ordinates to the same as the one underneath the the ‘when green flag clicked‘ block. This code makes the enemy move backwards and forwards forever. 6. Make your main character return to the start if they touch the enemy. Click on your main character sprite in the bottom left and then the Scripts tab. You need to copy the exact same code you made earlier to see if the main character is touching the wall , but this time you need to use: ...instead of the touching colour block. Click on the box in the block and select your Main Character . 7. New Levels Anchor 7 Coming Soon To be added soon. This concludes the walkthrough for a Scratch maze game! Try a combination of the suggestions below to add complexity to your game: Using ‘say ‘ or ‘think ‘ blocks in the Looks category to make your sprites say things at certain points (like at the start of a new level). Making your game harder by speeding up enemies in later levels (you could change the number of seconds it takes to glide ) Adding more enemies that only appear in harder levels. Setting a time limit – instead of having your time begin at 0 and increasing by 1 every second, have it start at 30 and decrease by 1 every second. Extensions Anchor 8
- Python | Section 3 Practice Tasks | CSNewbs
Test your understanding of data types, calculations and modulo. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. top Python - Section 3 Practice Tasks Task One: Square Number Create a program that asks the user to input a number and then prints the square of that number - to do this, multiply the number by itself . Remember: Break up variables and parts of a sentence in a print line by using commas. Example solutions: Enter a number: 12 The square of 12 is 144 Enter a number: 7 The square of 7 is 49 Task Two: Multiplying Numbers X Example solutions: Create a program that asks the user to input two numbers (num1 and num2 ). Multiply the two numbers together and print the total . Remember: Break up integer variables in a print line by using commas between each part of the sentence. Enter number one: 7 Enter number two: 9 7 x 9 = 63 Enter number one: 8 Enter number two: 12 8 x 12 = 96 Task Three: Turning 65 Example solutions: Create a program to input how old the user will turn this year and then print the year they will turn 65 . You could do this in just two lines but before trying that work out on paper the steps to calculating your own age you will turn 65. What steps did you take? Try to recreate those steps in Python. You might need to create another variable to make it easier. How old will you turn this year? 15 You will turn 65 in 2073 How old will you turn this year? 42 You will turn 65 in 2046 Task Four: Multiplication Table Let the user enter a number then print the first five multiplications in its times table. This can be done more simply when you learn about for loops but for now you will need to multiply the number by 1 , then multiply it by 2 etc. Try to make this program better by displaying the number and the value it is multiplied by in your print statements. Simple example solution: Enter a number: 8 8 16 24 32 40 Better example solution: Enter a number: 7 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 ⬅ 3b - Simple Calculations 4a - If Statements ➡
- Python | Extended Task 6 | CSNewbs
Test your ability to create a more complex program in Python based on a given scenario. Perfect for students learning GCSE Computer Science in UK schools. Extended Task 6 'Guess the Word' Game Create a Python program similar to the hit New York Times puzzle game Wordle . Allow the user to make guesses to match the randomly chosen hidden word , stopping when they get it correct. You can download a list of 5-letter words on this page. You will need to read in each line of the list and randomly select one - don’t forget to import the random library . Check if each letter of the user’s inputted word is in the randomly selected word . If you are using an IDE like Replit you can use the colorama library and the Fore command to turn the text: Green if the letter is in the correct position . Red if the letter is not in the selected word . Yellow if the letter is in the selected word but not in the correct position . Add your own flair and additional features to your program as an extension, including limiting the number of guesses and recording how many attempts it took to get the correct answer. Download a file of 534 5-letter words: For this task, you will need to create a document and include the following sections (with screenshots where appropriate): An introduction to explain the Purpose of your program . A List of Requirements for a successful program. Screenshots of your code (with comments in your code to show understanding). Testing – Create a plan to show how you will test your program and then explanations of any errors that you found and how they were fixed . An Evaluation of what worked, what didn’t, and how you met each of your requirements from your original list. Also, discuss further improvements that you could have made to improve your program. Reminders for this task: You will need a while loop to repeatedly allows the user to enter words until they match the correct word. Section 10 will help you to open, write and r ead from files . Download the file of 5-letter words from the link above. You will need to randomly select a word from the file. The choice command will help. Selection will be necessary to check if each letter in the inputted word matches the letter in the same position in the correct word. String handling is needed to select specific letters in a string. You will need to use .rstrip() on the selected line (word) that you have randomly chosen from the file. This removes any hidden characters that may interfere with checking if it is equal to the inputted word. There are multiple ways to approach this program, and your solution might look different from the example. Break the problem down and focus on one part at a time. Example solution: The word the user enters should be checked , letter by letter , against the letters in the same position in the randomly chosen correct word . Remember that the first letter in a word has the position 0 , not 1. Below is an example of some incomplete code you may wish to use in your solution. ⬅ Extended Task 5 (Colour Collection) Extended Task 7 (Number Game) ➡
- HTML Guide 5 - Images | CSNewbs
Learn how to embed images into your HTML web page using the img tag. Learn how to resize an image to your desired width and height. 5. Images HTML Guide Watch on YouTube: Images can be added to your web page to make it more visual. The guide below shows you how to find a picture online, download it and place it in your web page. Find & Save the Image Firstly you can perform a Google Image search to find a picture that you like. As an ethical Computer Scientist, you should be searching for copyright free images. Click on Tools and then Usage Rights to change it to 'Labeled for reuse'. Choose an appropriate image and download it to the same folder as your html file. Save the image in the same folder as where your HTML file is saved . If you don't do this, your image won't work . If you are using a school computer and the image automatically downloads , without giving you the option to rename it and save it, click on 'Show in folder' and move it to the folder where your HTML file is . Make sure that the image is saved in the exact same folder as your HTML file and that is has a suitable name . Create the Image Tag The tag for images does not have an end tag - it is all written within one set of angle brackets. src stands for source . You must type the image exactly as it is saved , including the file type (e.g. .jpg or .png). Don't forget the speech marks either. Create the img tag, using the exact name of the image you downloaded. Change the Image Size You can directly state the width and height of the image by defining the style within the image tag. If your image is too large or too small, change the size of it yourself. Next it is time to organise the web page further so it looks more like a professional site. 4. Hyperlinks HTML Guide 6. Organisation
- 4.2 - Signed Binary - Eduqas GCSE (2020 Spec) | CSNewbs
Learn about two methods of representing negative numbers in binary - sign and magnitude and two's complement. Based on the 2020 Eduqas (WJEC) GCSE specification. 4.2: Signed Binary Exam Board: Eduqas / WJEC Specification: 2020 + What are Sign and Magnitude and Two's Complement? Sign and Magnitude and Two's Complement are both methods of writing positive and negative binary values . Sign and Magnitude is simpler but will cause incorrect answers if used in binary calculations . Two's Complement is more complex but will generate correct answers when used in binary calculations . Sign & Magnitude The most significant bit (MSB ) is the largest bit of a binary number - the one furthest to the left . The MSB is the sign - it represents whether the binary value is positive or negative . If the sign is 0 then the binary number is positive . If the sign is 1 then the binary number is negative . The other bits represent the magnitude - the value of the binary number. For an 8-bit binary number , the range is -127 to 127 , because only 7 bits are used to define the magnitude. Sign & Magnitude: Problems Sign and magnitude is not commonly used by computers for two main reasons: Performing binary addition and subtraction (see section 4.3 ) will often cause a wrong result . In the example below, -7 + 3 should equal -4 but the result given is 2. + Sign and magnitude creates two different values for 0 - positive 0 and negative 0 which is incorrect. Two's Complement Two's complement is a method of representing positive and negative binary values. It is used often by computers because binary calculations will work correctly and there is only one value for zero. Two's Complement: Denary to Binary To represent a negative value using two's complement follow these steps: Write out the positive value in binary . Start on the right-hand side and move along, copy all 0s until you get to the first 1 . The first 1 is copied too. After the first 1 invert each value (change to its opposite ). So 0 becomes 1 and 1 becomes 0 . 1. 2. 3. Two's Complement: Binary to Denary To convert a binary number to denary using two's complement you must remember that the MSB is a negative value . Just add the numbers with 1 together to work out the denary value . Q uesto's Q uestions 4.2 - Signed Binary: Sign & Magnitude 1. Using sign and magnitude , convert the following values to denary : a. 00011101 b. 11100011 c. 10110110 d. 01001111 [1 each ] 2. Using sign and magnitude , convert the following values to binary : a. 83 b. -13 c. -102 d. -24 [1 each ] 3. Describe two problems when using sign and magnitude . [ 4 ] 4. Using sign and magnitude , the range of numbers that can be represented in 6 bits is from - 31 to + 31 . State the range of numbers that can be represented using sign and magnitude in the following bits: a. 8 bits b. 4 bits [1 each ] Two's Complement 1. Using two's complement , convert the following values to binary : a. -20 b. -49 c. -87 d. -113 [2 each ] 2. Using two's complement , convert the following values to denary : a. 10110010 b. 11101110 c. 01101011 d. 10011111 [2 each ] Watch the video to learn how sign and magnitude is used to represent negative numbers in binary . Watch the video to learn how two's complement is used to represent negative numbers in binary . Watch on YouTube Watch on YouTube 4.1 - Number Systems Theory Topics 4.3 - Binary Calculations
- Python | 7a - Procedures | CSNewbs
Learn how to create and use procedures in Python. Try practice tasks and learn through text and images. Perfect for students learning GCSE Computer Science in UK schools. top Python 7a - Procedures Subroutines A subroutine is a section of code that can be re-used several times in the same program. It is separate from the main code and has to be ‘called’ upon. Subroutines are designed to be repeated, and they have three key benefits: Subroutines make programs easier to read . They reduce the duplication of code . Complex problems are broken down into smaller chunks . There are two types of subroutines: procedures and functions . A procedure just executes commands , such as printing something a certain number of times. A function produces information by receiving data from the main program and returning a value to the main program. For example, a function could take the radius of a sphere from the main program, calculate a sphere’s area and return the value of the area to the main program. A function generally requires parameters to work – these are the values to be transferred from the main program to the subroutine. Procedures A procedure i s a type of subroutine that runs independently of the main program . A subroutine must be defined at the top of the program before the main code by typing def and the name of the subroutine . In the example below I have created a procedure to calculate the multiplication of two numbers and a separate procedure for the division. The main program starts beneath the subroutines , against the left side of the editor. I have created a while true loop that asks the user if they want to multiply, divide or stop the program. If they choose to multiply, the multiply subroutine is called . This initiates that subroutine then returns to the main program when it is complete. If they choose to divide, the divide subroutine is called instead. Typing stop will break (end) the loop. Here you can see the two parts of the program put together. Subroutines must be written first , with the rest of the program underneath. Subroutines can be called in any order . Below I have run the program and divided then multiplied before breaking the loop: Practice Tasks 1 1. Create a procedure called hello that just prints “Hello there! ”. In the main program create a for loop that calls the procedure 10 times. You must use a procedure. 2. Create a program with two procedures. The addition procedure allows the user to add two numbers together. The subtraction procedure allows the user to take a number away from another. Use a while true loop in the main program and a break to stop the loop. Example solution for #1: Local & Global Variables Programming languages use local variables and global variables . A global variable can be used anywhere in the program . A local variable can only be used in the subroutine it is created in . I have adapted the multiply / divide program below to use global variables by stating the global command and the name of the variables in each subroutine. This allows me to ask the user to enter numbers in the main program. Practice Tasks 2 1. Adapt your addition / subtraction program from the first practice task section to use global variables. 2. Create a program that asks the user to enter their name in the main program. Call a subroutine that greets the user using the name variables. You must use a procedure and a global variable . Example solution for #2: ⬅ Section 6 Practice Tasks 7b - Functions ➡
- 4.7 - Sound Representation - Eduqas GCSE (2020 Spec) | CSNewbs
Learn about how sounds are represented in a computer system including how analogue sound waves are converted into binary. Also, learn about sample rate, bit depth and metadata. Based on the 2020 Eduqas (WJEC) GCSE specification. 4.7: Sound Representation Exam Board: Eduqas / WJEC Specification: 2020 + Converting Analog Sound to Binary To store sound on a computer analog sound waves must be converted in to digital data ( binary ). The sound is sampled using an ADC (Analog to Digital Convertor) and stored as a binary value (such as 01010011) called a sample . 0010 1011 0101 0101 Analog sound wave ADC (Analog to Digital Converter) Binary sample Sampling an Analog Sound Wave Digital sampling is discrete (separate) and not continuous like analog waves. To get the highest quality sound, many samples are taken to recreate the analog wave as closely as possible . Sample Rate The sample rate is the number of samples taken per second . It is measured in kilohertz (kHz), for example CD quality is 44.1kHz (44,100 samples per second). The higher the sample rate , the better the audio quality as the digital data more closely resembles an analog wave . However, higher sample rates result in larger file sizes because more data is stored for each individual sample. A low sample rate will result in a low-quality sound because the digital data does not closely resemble the original analog wave . A higher sample rate will result in a higher-quality sound because the digital data more closely resembles the original analog wave . Improving Audio Quality Bit Depth Bit Rate The bit rate is defined as the amount of audio data processed per second . It is measured in kilobytes per second (kbps ). The bit rate is calculated by multiplying the sample rate and bit depth . Because the bit rate is the measure of the sample rate and bit depth multiplied together, the higher the bit rate the higher the quality of the sound . The bit depth is the number of bits available to represent each sample . For example, a sample with a bit depth of 4 could be 0101 or 0111 or 1010. A sample with a bit depth of 8 could be 01010110 or 1010110 or 11001111. A common bit depth is 16 bits . The higher the bit depth , the more bits are available to be used for each sample. Therefore the quality is often higher as the wave more closely resembles an analog wave . The file size will also be larger if the bit depth is higher, as each sample stores additional bits . Example: A short audio sample has a bit depth of 4 and a sample rate of 10 samples per second . The clip is 15 seconds long . Calculate the bit rate by multiplying the sample rate and bit depth : 4 bits x 10 = 40 bits . Now that is the correct data for one second. Multiply the bit rate by the number of seconds in the file: 40 x 15 = 600 bits . To convert the answer from bits to bytes , divide by 8 . 600 bits ÷ 8 = 75 bytes . Calculating File Size Metadata for Sound Files Music libraries such as Apple Music or Spotify store a huge amount of metadata on each song. Metadata is additional data about a file such as: Artist Title / Track Title Product / Album Title Track Number Date Created / Year Genre Comments Copyright Software Type Duration File size Bit rate Sampling rate Channels Volume Q uesto's Q uestions 4.7 - Sound Representation: 1. Explain how an analog sound wave is converted into a binary sample . [ 2 ] 2a. What is a sample rate ? [1 ] 2b. Explain two ways an audio file will be affected if the sample rate is increased . [4 ] 3a. What is bit depth ? [2 ] 3b. Explain two ways an audio file will be affected if the bit depth is increased . [4 ] 3c. Explain what the bit rate is. [ 2 ] 4 . An audio sample has a bit depth of 8 , a sample rate of 10 and it is 12 seconds long . What is the file size in bytes ? [ 2 ] 5a. What is metadata ? [ 2 ] 5b. State four different types of metadata for audio files . [4 ] low bit rate = lower quality high bit rate = higher quality Converting Analog Sound to Binary 1 4.6 Graphical Representation Theory Topics 4.8 - Compression










