Search CSNewbs

225 items found for ""

  • Python | 5b - Sleep | CSNewbs

    Python 5b - Sleep Why use Sleep? Sometimes in a program you will want to pause . You might want to do this: ​ To not overload a user with information all at once, As part of a timer program, To make it seem as if a program is loading or thinking. Using Sleep Start by importing sleep from the time library . To pause the program, simply write the word sleep followed by the number of seconds that you wish the program to break for in brackets . ​ Below is an example of a program that imports the sleep command and waits for 3 seconds between printing: You can implement the sleep command within a for loop to produce an effective timer that outputs each second waited to the screen: You could also use a variable instead of a fixed value with the sleep command such as below: Practice Task Create a slow calculator program that needs time to think in between calculations. ​ 1. Print a message to greet the user, then wait 3 seconds and ask them to enter a number. 2. Wait another 3 seconds and ask them to enter a second number. 3. Wait 2 seconds, print “Thinking…” then 2 seconds later print the total of the two numbers added together. Example solution: Embedded Python Editor Powered by trinket.io 5a - Random 5c - Date & Time

  • 2.5 - Compression - OCR GCSE (2020 Spec) | CSNewbs

    2.5: Compression Exam Board: OCR Specification: 2020 What is compression? To compress a file means to make its size smaller . Benefits of compression include: ​ Files take up less storage space (so more files can be stored). Files can be transferred quicker (because they are smaller). Files can be read from or written to quicker . ​ There are two methods that are used to compress files: Lossy and Lossless . Lossy Compression Lossy compression uses an algorithm (set of instructions) to analyse a file and remove data that cannot be heard or seen by humans . For example, a lossy algorithm would analyse the sound waves of an audio file and remove any frequencies which humans cannot hear. This process reduces the size of the file . ​ Further lossy compression will remove data that humans can see / hear . For example, the dog image to the right has been strongly compressed using a lossy algorithm and some data has clearly been removed. Lossy compression removes the data permanently , so the file can never return to its original form . ​ Lossy compression is often used with images , audio and video to reduce the file size, for example to send over the internet. Lossless Compression Lossless compression reduces the size of a file without permanently removing any data . Because of this, the file is returned to its original form when decompressed, so no quality is lost . ​ A file that is compressed with a lossless algorithm is usually larger than a file compressed with a lossy algorithm because no data has been permanently removed. Lossless compression is used with files that would not work if data was removed, for example executable files (e.g. programs and games) or word documents . Remember that lossy and lossless compression do not just refer to images. Below is an audio file that has been compressed with lossy compression . Data has been removed so the audio quality has decreased. 197 KB 81 KB 43 KB Q uesto's Q uestions 2.5 - Compression: 1. Describe 3 benefits of compressing a file . [ 3 ] 2. Describe the differences between lossy and lossless compression . [4 ] ​ 3. A student needs to compress a Microsoft Word document to send in an email. Suggest which type of compression they should use and why . [ 2 ] 2.4d Sound Storage Theory Topics 3.1a - Network Types & Performance

  • 2.2.2b - Object Oriented Programming | OCR A-Level | CSNewbs

    Exam Board: OCR 2.2b - Object Oriented Programming 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.2b - Object Oriented Programming: ​ 1. What is cache memory ? [ 2 ] ​ 2.2a - Computational Methods Theory Topics 3.1a - Algorithm Design

  • App Inventor 2 | Munchin' Pizza | CSNewbs

    App Inventor Task 3 - Munchin' Pizza This page will teach you how to make a simple app that changes pictures when a button is pressed . ​ You can make the app more complex by adding sounds or additional buttons. Step 1: Set up App Inventor 2 Open App Inventor 2 (use the button on the right) and create a new project. You will need to log in with a Google account. ​ Download the picture images from the zipped folder on the App Inventor 2 Basics page here . Once you have downloaded the pizza pictures you will need to upload them. Find the Media tab on the right side of App Inventor and click 'Upload File...' You will need to upload each picture individually. In the Palette tab on the left side, drag two buttons into the middle screen so they look like this: In the Components tab on the right, click on Button1 and click the Rename button at the bottom to change it to Pizza . Then Rename Button2 to Munch . This will help us when we code later as it will be less confusing. Click on the second button (Munch) that you just dragged into the centre then look in the Properties tab on the right and scroll down to Text . Change 'Text for Munch' to something like 'Munch Pizza' . Now click on the first button in the centre (Pizza) and in the Properties tab, click on Image and select the first image. ​ It should be the full slice of pizza. ​ When you have set the image, you might notice it goes a bit crazy. Still in the Properties tab, change the Height and Width to 'Fill parent...' for both. This will make the image fit within the boundaries of the screen. Finally, change the Text for the Pizza button to be blank. Otherwise it will appear on top of the pizza and look odd. So far you should have a button disguised as a pizza and another button that tells you to munch that lovely cheesy deliciousness. ​ If your program does not look like this, read the instructions above again carefully. Step 2: Code Click on the Blocks button in the top right to start adding code. In the Blocks tab on the left side click on Munch and drag the when Munch Click block into the centre. This block will execute any code inside of it whenever the munch button is clicked. In the Blocks tab on the left side click on Logic and drag an if then block and snap it inside the block you just dragged over. Click on the blue cog button and drag four else if blocks inside the if block at the bottom. ​ The blocks at the top will automatically update when you drag the blocks under the if block underneath. Because we are using different images, we need to check which image is currently being displayed, so we know which picture to change to. ​ Firstly we want to check if the first image is being displayed. Connect an = block from the Logic section. ​ Then add a Pizza Image block from the Pizza section. Lastly grab a " " block from the Text section and write the name of your first image inside (e.g. pizza1.jpg) Don't forget the extension (.jpg). But what does this code actually mean? It is checking to see what the current pizza image is. And if it is pizza1.jpg then it is going to... ​ ...change the picture to pizza2.jpg, as if someone has munched the pizza! ​ Grab a set Pizza Image to block from Pizza and then snap another " " block from Text and add the pizza2.jpg text inside. Now that we have written the code to check the current picture and move it to the next one when pressed, we just need to copy this for the other four pizza pictures. ​ Rather than select all the blocks again, right-clicking on the blocks and selecting 'Duplicate' will copy them. Copy each block and then change the values so that if pizza2.jpg is the current image, then it sets it to pizza3.jpg and so on. ​ Make sure that pizza5.jpg sets the image to pizza1.jpg so that it goes round in a loop. ​ Program 3 Complete! Step 3: Run The easiest way to run an app that you have created at home using App Inventor 2 is to download the free MIT AI2 Companion App on your smartphone from the Google Play Store . At the top of the App inventor program on your computer , click on Connect and AI Companion . This will generate a six-digit code you can type into your phone. ​ If your school has the emulator installed, you can also use this to test your app. Extra Step: Challenges 1. Create your own images and upload them . You can easily create your own set of pictures and link them together. Why not try: ​ Eating a different type of food (e.g. cookie or doughnut). A simple scene that changes from night to day. A simple character that changes appearance (like Pikachu powering up a thunder strike with each button press). 2. Add a sound effect whenever a button is pressed . In the video at the top of the page, you'll see I have a 'munch' sound whenever the button is pressed. You could record this sound yourself or use a sound effect site. ​ Once you have got your sound file (it should be short and .mp3) you need to upload it, just like you uploaded your images. In the Designer layout click 'Upload file...' in the Media tab on the right. Then look in the Palette tab on the left side, open the Media section and drag a Sound block into the centre. It will appear underneath the phone screen in a section called 'non-visible components' which is fine. ​ Now click on Properties on the right side and choose the sound file you just uploaded in the Source box. Click on the Blocks button in the top right to start adding the code! In the Blocks tab on the left side, click on Sound1 and drag the call Sound1 Play block directly underneath when Munch click . This will play the sound everytime the button is pressed. 3. Add more buttons . You could add a second clickable button which reverses the pattern and a third button that resets the order back to the first image. Adding new buttons is easy - drag them from the Palette tab in the Designer layout. Change the button text in the Properties tab and the name of the button in the Components tab. ​ To add code, click on Blocks in the top right then you can duplicate the code for Munch by right-clicking and choosing Duplicate. Now just change the values to what you want. If you are making a reset button, you don't need an if then statement, just set the image to your first image when the button is clicked. ​ Keep messing around with the program and have fun! KS3 Home Tasks 4, 5 & 6

  • Key Stage 3 Python | The Basics | CSNewbs

    Python - #1 - The Basics 1. Start with Commenting Programmers write A LOT of code. They need to understand exactly what they have written, especially if they are working as part of a team or returning to code after working on other projects. ​ To help them understand what they have written, programmers use comments to annotate (explain) their code . Task 1 - Create a new Python program and use # to write a comment that says your name and the date. Save the file as 1-Basics.py In Python, type the # symbol then your message to write a comment. ​ Comments are not printed when you run a program! ​ It is a good idea to start every program with a comment, so you know what the program is about . 2. Printing to the Screen The most basic and common command you will use in Python is print . ​ Inside the print brackets, you can write a message within speech marks . ​ Your print command should turn purple - don't use any capital letters in Python unless it is inside speech marks! Task 2 - Write a nice message by using the print command, brackets and speech marks. ​ Press F5 to run your program. 3. More Printing You can write multiple print lines one after another to print on different lines. Task 3 - Add two more print lines to your program. You can choose any message that you like. 4. New Lines You can use the special command \n to start a new line . This allows you to write on multiple lines but only use one print line. ​ Use the backslash ( \ ) not the forward-slash ( / ). Task 4 - Use \n to write a 3 sentence conversation in only one line of code. Challenge Programs Use everything that you have learned on this page to help you create these programs... ​ Challenge Task 1 - Days of the Week Create a new Python program. Save it as ' 1-Week.py ' Add a comment at the top with your name and the date. Create a program that prints the days of the week, with each day on a new line. ​ BONUS : Try to use only one print line. BONUS : Have no empty spaces at the start of each line. ​ When you run it, it should look like this: Challenge Task 2 - Conversation Create a new Python program. Save it as ' 1-Conversation.py ' Add a comment at the top with your name and the date. Create a program that prints a 6-line conversation between two people. It is up to you what these two people are talking about. ​ BONUS : Try to use only one print line. BONUS : Have no empty spaces at the start of each line. ​ When you run it, it could look something like this: #2 Variables >>>

  • Key Stage 3 Python | Turtle | CSNewbs

    Python - Iteration For Loops Editor Execute A for loop is a count controlled loop. ​ It repeats for a certain number of times as stated in the range brackets. ​ The first number (1) states the number to start on . ​ The second number is an exclusive end . This means it actually finishes on the number before . (11 will end on 10). You need a colon at the end of the loop line . ​ Each line to be repeated must be indented (press the tab key). ​ You can use the loop number within the loop itself. 1. Write a for loop to print your name 8 times . (Count it to double-check it prints eight times.) ​ 2. Use a for loop to print each number between 10 and 50 . ​ 3. Use a for loop from 1 to 10 . Print the 3 times table by multiplying number by 3 underneath the loop. ​ 4. Ask the user to input a whole number (call it num1 ). Write num1 in your range brackets to repeat any message that many times. 5. Ask the user to input a whole number (call it num1 ) and then input a word . Print the word by the number they entered . (Hint: Use num1 in the range.) ​ 6. Delete your code and copy these 3 lines: ​ #Delete the space after the colon for number in range(0,21,2):​ print(number) ​ What happens when you run this code? ​ 7. Use Q6 to help you print 0 to 100 , going up in 5s . Think about the 3 values you need in the range brackets. ​ 8. Use Q6 to help you print 100 down to 0 , backwards by 1 . Think about the 3 values you need in the range brackets. Tasks While Loops Editor Execute A while loop is a condition controlled loop . ​ While loops repeat as long as the condition is true . As soon as the condition becomes false , the loop will end . 1. Change the program in the editor to repeat the loop while a number is not equal to 33 . ​ 2. Make a new while loop that asks the user to enter a whole number . While the number is less than or equal to 1000 , keep repeating. ​ 3. Make a new while loop for while a colour is not equal to purple (or any colour you want). Ask the user to enter a colour inside of the loop . Don't forget to set colour to "" before you start. ​ 4. Edit your colour program to count how many guesses were made. Make a new variable called count and set it to 0 at the start of the program. Increase it by 1 in the loop, using count = count + 1 . 5. While a total is less than 100 , ask the user to input a decimal number . When it is over 100 , print ‘COMPUTER OVERLOAD’ . You need a variable called total . Increase the total each time with total = total + number . Don't forget to start it at 0 . Tasks != means ‘not equal to ’. The loop below will repeat as long as the password is not equal to “abc123” . Any variable you use in your condition must have a value first . You can’t check for your password if it doesn’t exist. That’s why I have written password = “” , to give password a value before we check it .

  • Python | Extended Task 3 | CSNewbs

    Extended Task 3 Hi, Susanna here, ​ I want to make a blackjack-like program that I can play for fun at home in between revising for Computer Science. ​ The aim of my blackjack game is to get as close to 21 as possible with the most number of cards, without going over. ​ So... The user can choose whether to be hit with a new card (a number between 1 and 8) or fold and stop. Each number they are dealt adds up to their total . If the total goes over 21, then they lose .​ If they bust (when over 21) or folded then their final number and their number of cards is displayed . Blackjack 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. Example solution: Helpful reminders for this task: Think about the type of loop that you need. Will you need more than one loop? What variables will you need? Remember to use an input . What will you ask the user? How will you use their response? Remember to use ‘import random’ and randint to create a random number . What outputs do you need and when? What should you display… After each hand? At the beginning? At the end? Extended Task 2 Extended Task 4

  • HTML Guide 9 - Colours & Fonts | CSNewbs

    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

  • Python | 1a - Printing | CSNewbs

    Python 1a - Printing Printing in Python To output a message onto the screen, use the print command. Then place your message within brackets and speech marks . For example: Try the embedded Python editor at the bottom of this page. When you run the program, the text will print to the Python console: Practice Task 1 1. Print your full name to the screen. ​ 2. On the next line, write another print statement to print t he name of the person (or thing) to your left. Example solution: Printing over Several Lines One way of writing across multiple lines is to write several print commands like this: = However, when we program, we always want to make our code the most efficient it can be by using as few lines as possible . ​ Therefore you can write \n within a printed statement to transfer it to the next line. = Both pieces of code display the same thing, but the second one is more efficient because it only uses one line. Practice Task 2 1. On line 1 print your first name to the screen. 2. On line 2 print your favourite colour. 3. On line 3 print your favourite movie. 4. Run the program. 5. Now re-write your program to print t he same output but using only line of code (Hint: use \n ) Example solution: Embedded Python Editor Powered by trinket.io Setting up Python 1b - Commenting

  • HTML Guide 1 - Setup | CSNewbs

    1. Setting up a HTML document HTML Guide Watch on YouTube: This guide assumes that you have Notepad++ already installed. ​ If you are working at home and need to download Notepad++ then click here . Save as .html file Notepad++ assumes you are writing a text file so you must change the file type . ​ Open Notepad++ ​ Click File then Save As... ​ Change Save as type: from Normal text file (.txt) to Hyper Text Markup Language file (.html) ​ Change File name: to Fanpage Website.html ​ These steps are necessary to set up your HTML web page correctly. Open Notepad ++ and save your file as a .html document. Editor vs. Browser View In newer versions of Notepad++ click on View then View Current File in and choose a browser installed on your computer such as Chrome . Some versions of Notepad++ enable you to view the document in a web browser by selecting Run then an option such as Launch in Chrome . It is good practice to have both Notepad++ and a web browser open at the same time so that you can easily check if any changes have been made correctly. ​ Remember to press the save icon ( ) before you refresh your browser . ​ Don't expect your web browser to show anything yet. Next it is time to add our essential tags for the structure of the web page. HTML Guide 2. Essential Tags