1/58
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is string manipulation?
The use of programming techniques to modify, analyse or extract information from a string.
What is case conversion?
The ability to change a string from one case to another, e.g. lowercase to uppercase.
What is length in string manipulation?
The ability to count the number of characters in a string.
What is a substring?
The ability to extract a sequence of characters from a larger string using slicing.
What is concatenation?
The ability to join two or more strings together to form a single string using the + operator.
What is ASCII conversion?
The ability to return an ASCII character from a numerical value and vice versa.
True or False? In Python substrings are indexed from 0.
True. In Python, substrings are indexed starting from 0, not 1. This is called 0-indexing.
name = "sarah". Write Python code to output the variable name in uppercase.
print(name.upper())
password = "letmein". Write Python code to output the length of the variable "password".
print(len(password))
FName = "Save", SName = "MyExams". Write Python code to output the two variables joined together.
How would you add a space?
print(FName + SName)
print|(FName + ““ + SName)
What is file handling?
The use of programming techniques to work with information stored in text files.
Write Python code to open a text file named "fruit.txt" in read only mode.
file = open("fruit.txt", "r")
Write Python code to close a text file.
file.close()
Write Python code to read a line from a text file.
file.readline()
Write Python code to write the value "Oranges" to an open text file.
file.write("Oranges")
What does "r" mode do when opening a file?
Opens a file in read-only mode.
What does "w" mode do when opening a file?
Opens a file in write mode, creating a new file if it doesn't exist, or overwriting an existing file.
What does "a" mode do when opening a file?
Opens a file in append mode, writing to the end of an existing file.
True or False? It's important to make a backup of text files before working with them.
True. Mistakes can lead to data loss.
What is a database?
An organised collection of data that allows easy storage, retrieval, and management of information.
What is a field?
One piece of information relating to one person, item or object, represented as a column in a database.
What is a record?
A collection of fields relating to one person, item or object, represented as a row in a database.
When are arrays useful for storing data?
When working with small amounts of data, stored in main memory (RAM).
Give two advantages of using a database.
Efficient sorting and searching of large amounts of data,
multiple user access,
better security than text files. (any two)
What is a disadvantage of using text files for data storage?
It can be difficult to know where one record begins and ends.
What is an advantage of using arrays for data storage?
They can be more efficient and faster to search than text files.
When are text files useful for data storage?
For storing small amounts of data on secondary storage when the application is closed.
What is SQL?
Structured Query Language - a programming language used to interact with a Database Management System (DBMS).
What does SELECT do in SQL?
Retrieves data (fields) from a database table. Example: SELECT name, age
What does FROM do in SQL?
Specifies the table(s) to retrieve data from.
What does WHERE do in SQL?
Filters the data based on a specified condition.
True or False? The '*' symbol is a wildcard in SQL.
True. It selects all fields in a table when used with SELECT.
What does SELECT * FROM Customers; do?
Selects all fields from the Customers table.
What does SELECT name, age FROM Customers WHERE age > 30; do?
Selects the name and age fields from the Customers table where age is greater than 30.
True or False? To select all fields, you must list each field name after SELECT.
False. Using SELECT * selects all fields.
Give an SQL command to select country and population from world table where population is less than 100,000.
SELECT country, population FROM world WHERE population < 100000;
What is a 1D array?
An ordered, static set of elements that can only store one data type. For example, a row in a table.
What is a 2D array?
An ordered, static set of elements that can only store one data type but adds another dimension. Visualised as a table with rows and columns.
Write Python code to create a 1D array named 'temp' with numbers 1-5.
temp = [1, 2, 3, 4, 5]
Write Python code to output element 2 of a 1D array named 'countries'.
print(countries[1])
Write Python code to modify element 3 in a 1D array named 'students' with the value "Rebecca".
students[2] = "Rebecca"
Write Python code to create a 2D array named 'scores' with values 1-9 in 3 rows and 3 columns.
scores = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
True or False? 2D arrays can store different data types in the same array.
False. Like 1D arrays, 2D arrays can only store one data type.
What does zero-indexing mean for arrays?
Indexes start from 0, not 1.
What is a function?
A sub-program that performs a specific task and returns a value.
What is a procedure?
A sub-program that performs a specific task but does not return a value.
What is a parameter?
A value passed into a sub-program (function or procedure).
True or False? To use a function or procedure it must be 'called'.
True.
What is a global variable?
A variable declared at the outermost level of a program that can be accessed from any part of the program.
What is a local variable?
A variable declared within a specific scope (e.g. a function) and can only be accessed within that scope.
What is the key difference between a function and a procedure?
A function returns a value; a procedure does not.
Write Python code to define a function named 'area' taking 2 parameters (length, width).
def area(length, width):
Write Python code to call a procedure named 'ageCheck' taking 1 parameter (21).
ageCheck(21)
Why are global variables generally discouraged?
They can be accessed and modified from anywhere, leading to potential bugs and hard-to-maintain code.
Why is random number generation used in programming?
It adds an element of unpredictability to a program.
True or False? Simulating the roll of a dice is an example of random number generation.
True.
How do you import the random module in Python?
import random
What does random.randint(a, b) do in Python?
Generates a random integer between a and b, inclusive.
Write Python code to randomly select a colour from 'red', 'blue', 'green', 'yellow' and output it.
import random; colours = ["Red", "Green", "Blue", "Yellow"]; random_colour = random.choice(colours); print(random_colour)