Unit 8 (Unit 3) Computer Science Flashcards
What are the three main building blocks of programming? (3)
- Sequence
- Selection
- Iteration
What is sequence in programming?
The specific order in which instructions or statements are executed in a program. It ensures operations happen in a logical and predictable order
What are data types?
Data types define the kind of data a variable can hold, such as numbers, text, or boolean values. They ensure data is processed and stored correctly by the system
How do data types enable appropriate storage?
Data types allow data to be stored in the right format, e.g. numbers as integers, characters as strings, etc
What is automatic validation in the context of data types?
The system automatically checks if the data matches the expected type and prevents errors
Note: This is a trick word in exams for CS they use validation which sounds confusing but it just means CHECKING
What is an integer in Pseudocode?
An integer is a positive or negative WHOLE number that can be used with mathematical operators (MUST be a whole number, cant be a decimal number)
What is a real number (float) in Pseudocode?
A real number is a positive or negative number WITH A DECIMAL and it can be used with mathematical operators (MUST be a decimal number, cant be a whole number)
What is a char in Pseudocode?
A char is a variable or constant that HOLDS a SINGLE character which can be letters, digits, or any printable symbol
What is a string in Pseudocode?
A string is a variable or constant that HOLDS MULTIPLE characters, which can be letters, digits, or any printable symbol. Strings can also be empty
What is a boolean in Pseudocode?
A boolean is a variable or constant that can have only two values: TRUE or FALSE
How do you get an integer input from a user with python (use age as an example)?
age = int(input(“Enter your age: “))
How do you get a real number (float) input from a user with python (use price as an example)?
price = float(input(“Enter the price: “))
What is Selection in programming?
Selection is a programming flow concept that allows the program to make decisions based on conditions
What is an If Statement?
It is a conditional statement that executes a block of code if its condition is true, otherwise it skips that block
What is an Else Statement?
An else statement provides an alternative to an if statement. It executes a block of code when the if condition is false
What is a Nested Statement?
Nested if statements allow one if statement inside another to check multiple conditions. They provide structure but can make code more complex.
What is a Case Statement?
Case statement checks a variable for different values and runs the code that matches the value
What is Selection in programming?
Selection allows a program to make decisions and choose different paths based on whether conditions are true or false
What do If Statements in programming allow?
It allows for branching outcomes in programs
What do Else Statements in programming allow?
It creates two possible paths, allowing the program to handle different scenarios efficiently
What do Case Statements in programming allow?
Helps people test a variable against several possible values. When a match is found, the corresponding code block executes
What are the benefits of selection in programming?
- Enables decision-making in programs.
- Makes applications user-responsive.
- Helps programmers create logical and efficient solutions.
What is Iteration in programming?
Iteration is the repetition of a block of instructions in a program. It can repeat a set number of times or until a condition is met, helping avoid repetitive code
What is a For Loop (Count Controlled)?
A for loop is a control flow statement that repeatedly executes a block of code a specified number of times, often used when you know how many times you want the code to run
What is a Repeat Until (Condition Controlled) loop?
A Repeat Until loop executes at least once. The condition is checked after the statements, and it stops when the condition is true
What is a While (Condition Controlled) loop?
While loop tests a condition before executing statements. The loop runs only if the condition is true and repeats the check after each execution. It ends when the condition becomes false.
What is Totalling in programming?
Totalling is the process of adding up values, often using a loop. A total variable is set to 0 at the beginning and updated during each loop iteration
What is Counting in programming?
Counting keeps track of how many times an event happens. A count variable is set to 0 and updated in each loop iteration based on the event
What is String HANDLING?
String handling is when you perform tasks on strings, such as joining two strings, slicing a string into parts, or finding out how many characters it contains
What is the Length method in string handling?
The Length method counts the number of characters in a string.
What is the Case Conversion method in string handling?
The Case Conversion method changes a string from one case to another, such as converting all characters to uppercase or lowercase
What is the Substring method in string handling and whats its use?
The Substring method allows you to extract a sequence of characters from a larger string. This can be useful for tasks like data validation or combining parts of strings
How is Substring extraction performed in Python?
Substring extraction is done using slicing. You specify a start and end position to get the desired characters from the string
In pseudocode, what is the starting position for extracting a Substring?
In pseudocode, the Substring starts at position 1 (not 0 as in Python)
What are Arithmetic Operators?
Arithmetic operators are used to perform basic mathematical operations in programming
What is the Addition operator and its pseudocode equivalent (how is it represented in pseudocode)?
Addition operator is used to add two numbers and in pseudocode it is written as +
What is the Subtraction operator and its pseudocode equivalent?
Subtraction operator is used to subtract one number from another and in pseudocode, it is written as -
What is the Multiplication operator and its pseudocode equivalent?
Multiplication operator is used to multiply two numbers and in pseudocode, it is written as *
What is the Division operator and its pseudocode equivalent?
Division operator is used to divide one number by another and in pseudocode, it is written as /
What is the Modulus operator and its pseudocode and python equivalent (how is it represented in pseudocode and python)?
Modulus operator returns the remainder after division. In Python, it is written as %. In pseudocode, it is written as MOD
What is the Quotient operator and its pseudocode and python equivalent?
Quotient operator returns the whole number result of division. In Python, it is written as //. In pseudocode, it is written as DIV
What is Exponentiation, and its pseudocode equivalent?
Exponentiation makes a number to the power of another number. In Python, it is written as **. In pseudocode, it is written as ^
What are the examples of Comparison operators?
- ==
- <>
- <
- <=
- >
- > =
What is the Equal to operator and its pseudocode equivalent?
The Equal to operator checks if two values are the same and in pseudocode, it is written as ==.
What is the Not equal to operator and its pseudocode equivalent?
The Not equal to operator checks if two values are different and in pseudocode, it is written as <>
What is the Less than operator and its pseudocode equivalent?
The Less than operator checks if one value is smaller than another and in pseudocode, it is written as <
What is the Less than or equal to operator and its pseudocode equivalent?
The Less than or equal to operator checks if one value is smaller than or equal to another and in pseudocode, it is written as <=
What is the Greater than operator and its pseudocode equivalent?
The Greater than operator checks if one value is larger than another and in pseudocode, it is written as >
What is the Greater than or equal to operator and its pseudocode equivalent?
The Greater than or equal to operator checks if one value is larger than or equal to another and in pseudocode, it is written as >=
How many main Boolean operators are there, and what are they (name them)?
There are three main Boolean operators: AND, OR, and NOT
What does the AND operator do in Boolean logic?
The AND operator checks if two conditions are both true. If both conditions are true, the result will be True
What does the OR operator do in Boolean logic?
The OR operator makes the statement True if at least one of the conditions is true. If both conditions are false, only then will the result be False
What does the NOT operator do in Boolean logic?
The NOT operator reverses the condition, making the statement True if the condition is False, and making the statement False if the condition is True
What does “return” mean in a function?
“Return” sends the result of the function back to where it was called so it can be used later
What is a Function?
A function is a subprogram that performs a specific task and returns a value. It is used to carry out calculations, retrieve data, or process information based on input
What is a Procedure?
A procedure is a subprogram that performs a specific task but does not return a value. It is used to carry out actions like printing output or modifying data
Why are Functions & Procedures used in programming (3 reasons and explain)?
- Organise code: Break the program into more manageable parts.
- Avoid repeating code: Can be reused throughout the program to avoid repeating code.
- Perform tasks: Used for calculations, retrieving data, or making decisions based on inputs.
What are parameters in programming?
Parameters are values that are passed into a subprogram to be used within that subprogram
What can parameters be in a subprogram?
Parameters can be variables or values that are placed in brackets after the subprogram’s name
How are functions defined in pseudocode and Python?
In pseudocode, functions are defined using the FUNCTION keyword, and in Python, they are defined using the def keyword
What is a local variable?
A local variable is a variable created inside a specific part of the program
Where can a local variable be used?
A local variable can only be used inside the part of the program where it was created
What happens to a local variable after its part of the program ends?
When the program moves past the section, the local variable is deleted and the space it used is freed
What is a global variable?
A global variable is a variable that is declared outside of any functions or procedures, at the outermost level of the program (ususally at the start)
Where can a global variable be used?
A global variable can be accessed and modified from anywhere in the program, including inside functions and procedures
What does a global scope mean?
It is a variable that can be accessed and modified from any part of the program
Do global variables have a global scope?
Yes
What is a Library Routine?
A library routine is reusable code that can be used throughout a program
Why are Library Routines Useful?
Saves time by allowing people to use pre-written code which reducing the need to write the same code repeatedly making it EFFICIENT
Examples of Library Routines: (2)
- Random (for generating random numbers)
- Round (for rounding numbers)
What is the Random library?
The random library allows the user to make use of ‘random’ in their programs, such as generating random numbers or making random choices
What is random number generation?
When a computer generates a random number to be used in a program
Examples of using the Random library:
- Simulating a dice roll
- Selecting a random question
- National lottery
- Cryptography
What is the Round library?
It allows people to round numbers to a set amount of decimal places
How are easy-to-maintain programs written?
Easy-to-maintain programs are written using techniques that make code easy to read and understand. These techniques include layout, indentation, comments, and more
What is the layout technique?
It is when you have spacing between sections
What is the indentation technique?
It is when you have clearly defined sections of code
What is the use of comments in programming?
Comments are used to explain key parts of the code.
(They do not affect the execution but help people understand what the code does)
What is the use of Intuitive Variable names?
It is to describe what is being stored
What is the use of white space?
To make the code easy to read
What is the use of Sub-programs?
to add functions or procedures used where possible
What is an array?
An array is an ordered, static set of elements stored in a fixed-size memory location
How many types of data can an array store?
Only 1
What is a 1-dimensional array?
It is a linear array where elements are stored in a single line
What does it mean when an array is zero-indexed?
Zero-indexed means that the indexes of the array elements start at 0
What is a 2D array?
A 2D array has 2 dimensions, creating a table with rows and columns
How can a 2D array be visualised?
A 2D array can be visualised as a table with rows and columns
How do you navigate through a 2D array?
To navigate through a 2D array, you first go down the rows and then across the columns to find a position
What is file handling?
File handling refers to using programming techniques to work with information stored in text files
What are examples of file handling techniques?
Examples of file handling techniques include opening text files, reading text files, writing text files, and closing text files