top of page

Search CSNewbs

287 items found for ""

  • Python | 5d - Colorama | CSNewbs

    top Python 5d - COlorama What is Colorama? Colorama is a library that allows the colour of text to be changed. ​ Information about the library can be found on the Python Package Index (PyPi) website . Copyright of the library is held by Jonathan Hartley & Arnon Yaari. ​ Colorama can be imported when using some online editors like Replit . ​ Colorama is not available as a default library on the standard Python offline editor (IDLE) . Using Colorama The three main commands using Colorama are: ​ Fore to change the text colour. Back to change the highlight colour. Style to make the text appear dim or bright. from colorama import Fore print (Fore. GREEN + "Hello There" ) Hello There from colorama import Back print (Back.YELLOW + "Goodbye Now" ) Goodbye Now from colorama import Style print (Style.DIM + "Hi Again" ) Hi Again There are 8 possible colours to choose with the Fore and Back commands. You must write the colour name in CAPITAL LETTERS . ​ BLACK CYAN GREEN MAGENTA RED WHITE YELLOW There is also the RESET option, e.g. Fore.RESET The 2 options to choose with the Style command are DIM and BRIGHT . You can also use Style.RESET_ALL Colorama Task 1 ( Traffic Lights) Create a simple traffic light program . ​ The user is prompted for an input . Typing "GO " will output a suitable message in GREEN , typing "WAIT " will output a message in YELLOW and typing "STOP " will output a response in RED . Example solutions: What should the driver do? STOP You must stop your car. What should the driver do? GO It is safe to continue driving. ⬅ 5c - Date & Tim e 5e - M ore Libraries ➡

  • 2.2 - Data Types - OCR (2020 Spec) | CSNewbs

    2.2: Data Types Exam Board: OCR Specification: 2020 What are the different data types? When programming, variables should be given appropriate data types . Character A single character , such as a letter, number or punctuation symbol. ​ Examples: T 8 ? String A sequence of characters , including letters, numbers and punctuation. ​ Examples: Harry Waters 14:50pm Ice Age 4 Integer A whole number . ​ ​ ​ Examples: 475 -8432 56732 Real Boolean A decimal number . ​ ​ Examples: 65.3 -321.1234 909.135 An answer that only has two possible values . ​ Examples: True / False Yes / No 0 / 1 Telephone numbers are always stored as a string , not an integer. Casting Converting the value of a variable from one data type into another is known as casting . ​ Python automatically assumes an input is a string so the int() command is used to cast an input into an integer . Other Python commands for casting include str() and float() . ​ For example: age = int(input("Enter your age: ")) Q uesto's Q uestions 2.2 - Data Types: ​ 1. List the five data types , giving an example of each . [ 5 ] ​ 2. State which data type is most suitable for the following variables: a. Age [ 1 ] b. Surname [ 1 ] c. Height (in metres) [ 1 ] d. First Initial [ 1 ] e. Phone number [ 1 ] f. Right-Handed? [ 1 ] ​ ​ 3. Explain what casting is and give a programming situation in which it would be used . [ 2 ] 2.1 - Programming Fundamentals Theory Topics 2.3 - Additional Techniques

  • 1.2 - Storage Media | Unit 2 | OCR Cambridge Technicals | CSNewbs

    1.2 - Storage Media Exam Board: OCR Specification: 2016 - Unit 2 Data can be stored on a variety of storage media , each with its own benefits and drawbacks . Magnetic Storage Optical Storage A magnetic hard disk drive (HDD ) is the most common form of secondary storage within desktop computers. A read/write head moves nanometres above the disk platter and uses the magnetic field of the platter to read or edit data. Hard disk drives can also be external and connected through a USB port . An obsolete (no longer used) type of magnetic storage is a floppy disk but these have been replaced by solid state devices such as USB sticks which are much faster and have a much higher capacity. Another type of magnetic storage that is still used is magnetic tape . Magnetic tape has a high storage capacity but data has to be accessed in order (serial access ) so it is generally only used by companies to back up or archive large amounts of data . Optical storage uses a laser to project beams of light onto a spinning disc, allowing it to read data from a CD , DVD or Blu-Ray . ​ This makes optical storage the slowest of the four types of secondary storage. ​ Disc drives are traditionally internal but external disc drives can be bought for devices like laptops. Magnetic Storage Characteristics: ​ ✓ - Large CAPACITY and cheaper per gigabyte than solid state . ​ X - Not DURABLE and not very PORTABLE when powered on because moving it can damage the device. ​ ✓ - Relatively quick ACCESS SPEED but slower than Solid State . ​ Optical Storage Characteristics: ​ X - Low CAPACITY : 700 MB (CD ), 4.7 GB (DVD ), 25 GB (Blu-ray ). X - Not DURABLE because discs are very fragile and can break or scratch easily. ✓ - Discs are thin and very PORTABLE . ​ X - Optical discs have the Slowest ACCESS SPEED . ​ ​ Magnetic Disks are spelled with a k and Optical Discs have a c. Solid State Storage Paper Storage There are no moving parts in solid state storage. SSD s (Solid State Drives ) are replacing magnetic HDDs (Hard DIsk Drives) in modern computers and video game consoles because they are generally quieter , faster and use less power . SSDs can also be external . ​ A USB flash drive ( USB stick ) is another type of solid state storage that is used to transport files easily because of its small size. ​ Memory cards , like the SD card in a digital camera or a Micro SD card in a smartphone , are another example of solid state storage. Paper storage includes printed or hand-written documents, notes, forms, schedules and maps. Paper is relatively inexpensive in small quantities but it can take up a lot of space compared to small devices like USB sticks. Producing paper is environmentally damaging and requires physical security methods to keep safe. ​ Paper, such as a timetable, can be written on if times change and easily carried on a person. However, paper in the form of an essay must be re-printed to add changes . Solid State Characteristics: ​ ✓ - High CAPACITY but more expensive per gigabyte than magnetic . ​ ✓ - Usually DURABLE but cheap USB sticks can snap or break . ​ ✓ - The small size of USB sticks and memory cards mean they are very PORTABLE and can fit easily in a bag or pocket. ​ ✓ - Solid State storage has the fastest ACCESS SPEED because they contain no moving parts . Paper Storage Characteristics: ​ X - Low CAPACITY as each page can only hold a certain amount of information. Paper also takes up physical space . ​ X - Poor DURABILITY as paper can easily tear and become damaged in rain. ​ ✓ / X - PORTABILITY varies as single sheets of paper can be easily folded and placed in a pocket. However, large stacks of paper can be difficult and expensive to transport. ​ X - Paper's ACCESS SPEED , in terms of searching for a specific item, is slow , especially if the paper storage has not been organised efficiently . Q uesto's Q uestions 1.2 - Storage Media: ​ 1. State 3 examples of each type of storage media . For example, a CD for optical storage. [3 each ] ​ 2. Compare each type of storage media in terms of capacity , durability , portability and access speed . You may decide to do this as a table or poster. [16 ] ​ 3. Identify the most suitable device (not the media ) and justify its suitability for the following scenarios: a. Backing up a large database at the end of each day. [5 ] b. Keeping a copy of a cleaning schedule for hotel staff. [5 ] c. Making copies of a promotional video to hand out to audience members at a dancing event. [5 ] 1.1 - Holders of Information Topic List 1.3 - Access & Storage Devices

  • 10.1 - Translators - Eduqas GCSE (2020 Spec) | CSNewbs

    10.1: Translators Exam Board: Eduqas / WJEC Specification: 2020 + What is a translator? A translator changes (translates) a program written in one language into another language (usually machine code ). There are three types of translator : Assembler An assembler converts low level assembly language into machine code . INP STA 33 INP STA 34 LDA 33 ADD OUT HLT Interpreter An interpreter converts high-level language one line at a time into machine code and executes it. PYT HON Compiler A compiler converts high-level language into machine code for execution at a later time. The entire program is converted at once . PYT HON 0010 1011 0101 0101 0110 0111 0101 0001 0101 0101 0010 1011 0101 0101 0110 0111 0101 0001 0101 0101 0010 1011 0101 0101 0110 0111 0101 0001 0101 0101 Differences between an interpreter and a Compiler: Interpreter Compiler Execution Method: An interpreter translates source code (high level code) into machine code one line at a time . ​ Execution Speed: An interpreter is slower than a compiler because the code must be reinterpreted each time the program is run. ​ Complexity: Interpreters are smaller, simpler programs . ​ Error Reporting: In error reporting, the interpreter would encounter the errors and report it to the user immediately and stops the program from running.​ ​ Repetition: Interpreted programs can be edited and run without translating the whole program . Interpreters must reinterpret the program every time it is run. Execution Method: A compiler translates all the source code (high level code) into machine code in one go . A compiler produces an executable file that will run on other machines without the compiler needing to be installed. ​ Execution Speed: Compilers can produce much more efficient code than interpreters making the compiled programs run faster . ​ Complexity: Compilers tend to be large complex programs . ​ ​ Error Reporting: The compiler would analyse the entire program , taking note of where errors have occurred and record them in an error file . ​ Repetition: Compilation requires analysis and the generation of the code only once , whereas interpreters must re-interpret each time. However, compiled programs have to be re-compiled after any changes have been made. x1 ∞ x1 Q uesto's Q uestions 10.1 - Translators: ​ 1. Briefly describe each type of translator : a. Assembler [ 1 ] b. Interpreter [ 2 ] c. Compiler [ 2 ] ​ 2. Compare interpreters and compilers for each of the following features : a. Execution Method b. Execution Speed c. Complexity d. Error Reporting e. Repetition [ 10 total ] 9.1 - IDE Tools Theory Topics 10.2 - Stages of Compilation

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

    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

  • 3.1 - Data vs Information | Unit 2 | OCR Cambridge Technicals | CSNewbs

    3.1 - Data vs. Information Exam Board: OCR Specification: 2016 - Unit 2 The terms 'data ' and 'information ' are often used interchangeably but they do not mean the same thing . The term 'data ' refers to unprocessed facts or statistics that have no context . ​ For example, 53% is data - it is a statistic that has no context. The term 'information ' refers to data that has been processed , organised and structured into context . ​ For example, 53% of pumpkin stock was sold in 2019 is information - it is data that has been given context (meaning). Data Processing Information Q uesto's Q uestions 3.1 - Data vs. Information: ​ 1. Describe , using examples , the difference between data and information . [4 ] 2.4 - Information Management 3.2 & 3.3 - Information Categories Topic List

  • 3.9 - Protection Against Threats - GCSE (2020 Spec) | CSNewbs

    3.9: Protection Against Threats Exam Board: Eduqas / WJEC Specification: 2020 + Network Forensics & Penetration Testing What is network forensics? Network forensics is the monitoring of a network to identify unauthorised intrusions . Network forensics is used to record and analyse attacks on a network and to gather other information about how the network is performing. ​ It is important for organisations to identify weaknesses in their networks so that they can fix them and be prepared for any type of attack or malware. ​ Footprinting - Footprinting is one method of evaluating a network’s security . This is when a security team puts itself in the attacker’s shoes by obtaining all publicly available information about the organisation and its network . Footprinting allows the company to discover how much detail a potential attacker could find out about a system. The company can then limit the technical information about its systems that is publicly available . Penetration Tests Penetration tests are carried out as part of ethical hacking. Ethical hacking is when an organisation gives permission to specific 'good ' hackers to try and attack a system so that the weak points can be highlighted and then fixed. The purpose of a penetration test is to review the system's security to find any risks or weaknesses and to fix them . ​ There are four main types of penetration tests : Internal tests are to see how much damage could be done by somebody within the company with a registered account. External tests are for white hat hackers to try and infiltrate a system from outside the company . Blind tests are done with no inside information , to simulate what a real attacker would have to do to infiltrate the system. + Targeted tests are conducted by the company's IT department and the penetration team cooperating together to find faults in the system. Anti-Malware & Firewalls Anti-Malware Software Anti-malware software is used to locate and delete malware, like viruses, on a computer system. The software scans each file on the computer and compares it against a database of known malware . Files with similar features to malware in the database are identified and deleted . There are thousands of known malware, but new forms are created each day by attackers, so anti-malware software must be regularly updated to keep systems secure. Other roles of anti-malware software: Checking all incoming and outgoing emails and their attachments . Checking files as they are downloaded . Scanning the hard drive for viruses and deleting them . Firewall A firewall manages incoming and outgoing network traffic . Each data packet is processed to check whether it should be given access to the network by examining the source and destination address . ​ Unexpected data packets will be filtered out and not accepted to the network. Other roles of a firewall include: Blocking access to insecure / malicious web sites . Blocking certain programs from accessing the internet . Blocking unexpected / unauthorised downloads . Preventing specific users on a network accessing certain files . Other Methods of Protection Double Authentication Also known as two-factor authentication (2FA ), this is a method of confirming someone's identity by requiring two forms of authorisation , such as a password and a pin code sent to a mobile. 4392 Secure Passwords Usernames must be matched with a secure password to minimise the chances of unauthorised users accessing a system. ​ Passwords should contain a mix of uppercase and lowercase letters , punctuation and numbers . Passwords should be of a substantial length (at least 8 characters) and should be regularly changed . ******** User Access Levels Access levels are used to only allow certain users to access and edit particular files. ' Read-Only ' access is when a user can only view a file and is not allowed to change any data . ​ For example, a teacher might set homework instructions as read-only for students to view. ' Read and Write ' access allows a user to read and edit the data in a file. ​ For example, a teacher might set an online workbook as read and write access for students to fill in. It is important to set access levels so that only authorised users can view and change data. The more users who have access to a file, the more likely it is to be compromised. Certain users may also have no access to a file - when they can't view or edit it. Encryption Encryption is the process of scrambling data into an unreadable format so that attackers cannot understand it if intercepted during transmission. ​ The original data (known as plaintext ) is converted to scrambled ciphertext using an encryption key . Only at the correct destination will the encryption key be used to convert the ciphertext back into plaintext to be understood by the receiving computer. ​ A very simple method of encryption is to use the XOR logical operator . XOR is used on the plaintext and key together to create the ciphertext . Using XOR again on the ciphertext and key will reverse the encryption to reveal the plaintext . Encryption using XOR Plaintext = 00110100 Key = 10100110 XOR Ciphertext = 10010010 Decryption using XOR ​ Ciphertext = 10010010 / Key = 10100110 XOR Plaintext = 00110100 Q uesto's Q uestions 3.9 - Protection Against Threats: ​ 1a. What is network forensics ? Why is it important ? [ 3 ] 1b. Explain what is meant by footprinting and why companies do it . [ 2 ] 2. What is an ethical hacker ? [2 ] 3a. Describe the purpose of penetration tests . [2 ] 3b. Describe each type of penetration test . [ 8 ] ​ 4. Describe the purpose of anti-malware software and its different roles . [ 4 ] 5. Describe the purpose of a firewall and its different roles . [ 4 ] ​ 6a. Describe double authentication . [2 ] 6b. State three rules for choosing a strong password . [ 3 ] 7. Describe the three types of access level . [6 ] 8a. Describe the purpose of encryption . [ 2 ] 8b. Explain how encryption works, using the terms plaintext , key and ciphertext . [ 4 ] 3.8 - Cyber Threats Theory Topics 4.1 - Number Systems

  • 3.3d - Network Security & Threats | OCR A-Level | CSNewbs

    Exam Board: OCR 3.3d - Network Security & Threats 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.3d - Network Security & Threats: ​ 1. What is cache memory ? [ 2 ] ​ 3.3c - Network Hardware & DNS Theory Topics 3.4a - Web Technologies

  • 2.2b - Translators & Compilation | OCR A-Level | CSNewbs

    Exam Board: OCR 2.2b: Translators & Compilation 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 - Translators & Compilation: ​ 1. What is cache memory ? [ 2 ] ​ 2.2a - Applications & Utilities Theory Topics 2.3 - Software Development

  • 2.4b - Assembly Language | OCR A-Level | CSNewbs

    Exam Board: OCR 2.4b: Assembly Language 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.4b - Assembly Language: ​ 1. What is cache memory ? [ 2 ] ​ 2.4a - Programming & Pseudocode Theory Topics 2.4c - Object-Oriented Language

  • Python | Setting up Python | CSNewbs

    Setting up Python Downloading Python If you are using Python in Computer Science lessons, then your school should already have it downloaded and installed on the school computers. ​ It is a good idea to download it on a home computer too so you can practice outside of lessons. Python is free and can be downloaded from the official website. You should download the most up-to-date version of Python 3. ​ Save the file and then run it to start installing. Official Download Page Using Python When you run the Python application, it will open the shell. This window will display the outputs of any program you have created. ​ Do not type into the shell . ​ Click on the File tab then New File to open the editor. Python Shell - This displays the outputs of your program. Do not write directly into the shell . Python Editor - All code is written into the editor. When you want to test a program press the F5 key (or click the Run tab then Run Module ). The first time you test a program, it will prompt you to save the file. Make sure you save it somewhere you will remember - it is a good idea to create a folder named 'Python' where you can keep all your practice programs. The next page looks at actually creating a program but above shows how code has been typed into the editor and then displayed in the shell. ​ You never need to save the shell window. Also, the editor saves automatically every time you run the program. Opening a Saved Program When you want to re-open and edit a file you have created previously double-clicking on it won't work . ​ Right-click on the file and select Edit with IDLE : https://trinket.io/python/76b41b35c5 1 a - Printing ➡

  • Key Stage 3 Python | Selection | CSNewbs

    Python - #5 - Selection 1. Using if Statements Using if enables your program to make a choice . ​ There are a few things you need to remember : if is lowercase - it should turn orange. You must use double equals == You need a colon : at the end of your if line. The line below your if line must be indented . ​ Task 1 - Create a new Python program and save the file as 5-Selection.py ​ Use the picture to help you ask what your favourite food is . Run the program and test it works. To indent a line press the tab key on your keyboard. ​ Indentation is important as it tells Python what is within the if statement and what isn't. 2. Using elif elif stands for 'else if '. It is used to respond in a different way depending on the input. ​ elif works exactly the same as an if line so if you make a mistake look up at task 1 to help you. Task 2 - Write an elif line that responds differently to your favourite food question from task 1. e.g. "Yum!" if someone enters "pasta". 3. Using else It is impractical to have hundreds of elif lines to respond to different inputs. ​ else is used to respond to anything else that has been entered in a general way. ​ The else line works a bit differently, so look carefully at the picture . Task 3 - Write an else line that responds to anything else the user enters for your favourite food question. 4. Multiple elifs Despite what you did in task 3, programs can be expanded with more than one elif line. ​ Underneath your first elif line but before your else line, add at least two more elif sections that respond differently depending on what is entered. ​ Use the elif line from the task 2 picture to help you. Task 4 - Read the description above and use task 2 to help you. Challenge Programs Use everything that you have learned on this page to help you create these programs... ​ Challenge Task 1 - Spanish Translation Create a new Python program. Save it as ' 5-Translator.py ' Add a comment at the top with your name and the date. Create a program that asks for a number between 1 and 4. Use if and elif statements to see what the user has entered and print a statement that displays the chosen number in Spanish - use the image to help you understand. ​ BONUS : Add an else line for any numbers higher than 4. ​ ​ When you run it, it could look something like this: Challenge Task 2 - Able to Vote Create a new Python program. Save it as ' 5-Vote.py ' Add a comment at the top with your name and the date. Create a program that asks for their age. Use an if statement to see if the age is more than 17 (use > instead of ==). If the age is over 17, then print "You are old enough to vote!" Use an else statement to print a different message for everyone else. ​ ​ When you run it, it could look something like this: Challenge Task 3 - Totals Create a new Python program. Save it as ' 5-Totals.py ' Add a comment at the top with your name and the date. Use an int input line to ask the user for number 1. Use an int input line to a sk the user for number 2. Multiply the two numbers together and save it into a variable called total. If the total is over 9000, then print "It's over 9,000!!!" Use an else statement to print the total if it is less than 9000. ​ ​ When you run it, it could look something like this: <<< #4 Calculations #6 Turtle >>>

bottom of page