Additional Programming Techniques (2)

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/58

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:51 AM on 4/9/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

59 Terms

1
New cards

What is string manipulation?

The use of programming techniques to modify, analyse or extract information from a string.

2
New cards

What is case conversion?

The ability to change a string from one case to another, e.g. lowercase to uppercase.

3
New cards

What is length in string manipulation?

The ability to count the number of characters in a string.

4
New cards

What is a substring?

The ability to extract a sequence of characters from a larger string using slicing.

5
New cards

What is concatenation?

The ability to join two or more strings together to form a single string using the + operator.

6
New cards

What is ASCII conversion?

The ability to return an ASCII character from a numerical value and vice versa.

7
New cards

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.

8
New cards

name = "sarah". Write Python code to output the variable name in uppercase.

print(name.upper())

9
New cards

password = "letmein". Write Python code to output the length of the variable "password".

print(len(password))

10
New cards

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)

11
New cards

What is file handling?

The use of programming techniques to work with information stored in text files.

12
New cards

Write Python code to open a text file named "fruit.txt" in read only mode.

file = open("fruit.txt", "r")

13
New cards

Write Python code to close a text file.

file.close()

14
New cards

Write Python code to read a line from a text file.

file.readline()

15
New cards

Write Python code to write the value "Oranges" to an open text file.

file.write("Oranges")

16
New cards

What does "r" mode do when opening a file?

Opens a file in read-only mode.

17
New cards

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.

18
New cards

What does "a" mode do when opening a file?

Opens a file in append mode, writing to the end of an existing file.

19
New cards

True or False? It's important to make a backup of text files before working with them.

True. Mistakes can lead to data loss.

20
New cards

What is a database?

An organised collection of data that allows easy storage, retrieval, and management of information.

21
New cards

What is a field?

One piece of information relating to one person, item or object, represented as a column in a database.

22
New cards

What is a record?

A collection of fields relating to one person, item or object, represented as a row in a database.

23
New cards

When are arrays useful for storing data?

When working with small amounts of data, stored in main memory (RAM).

24
New cards

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)

25
New cards

What is a disadvantage of using text files for data storage?

It can be difficult to know where one record begins and ends.

26
New cards

What is an advantage of using arrays for data storage?

They can be more efficient and faster to search than text files.

27
New cards

When are text files useful for data storage?

For storing small amounts of data on secondary storage when the application is closed.

28
New cards

What is SQL?

Structured Query Language - a programming language used to interact with a Database Management System (DBMS).

29
New cards

What does SELECT do in SQL?

Retrieves data (fields) from a database table. Example: SELECT name, age

30
New cards

What does FROM do in SQL?

Specifies the table(s) to retrieve data from.

31
New cards

What does WHERE do in SQL?

Filters the data based on a specified condition.

32
New cards

True or False? The '*' symbol is a wildcard in SQL.

True. It selects all fields in a table when used with SELECT.

33
New cards

What does SELECT * FROM Customers; do?

Selects all fields from the Customers table.

34
New cards

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.

35
New cards

True or False? To select all fields, you must list each field name after SELECT.

False. Using SELECT * selects all fields.

36
New cards

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;

37
New cards

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.

38
New cards

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.

39
New cards

Write Python code to create a 1D array named 'temp' with numbers 1-5.

temp = [1, 2, 3, 4, 5]

40
New cards

Write Python code to output element 2 of a 1D array named 'countries'.

print(countries[1])

41
New cards

Write Python code to modify element 3 in a 1D array named 'students' with the value "Rebecca".

students[2] = "Rebecca"

42
New cards

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]]

43
New cards

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.

44
New cards

What does zero-indexing mean for arrays?

Indexes start from 0, not 1.

45
New cards

What is a function?

A sub-program that performs a specific task and returns a value.

46
New cards

What is a procedure?

A sub-program that performs a specific task but does not return a value.

47
New cards

What is a parameter?

A value passed into a sub-program (function or procedure).

48
New cards

True or False? To use a function or procedure it must be 'called'.

True.

49
New cards

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.

50
New cards

What is a local variable?

A variable declared within a specific scope (e.g. a function) and can only be accessed within that scope.

51
New cards

What is the key difference between a function and a procedure?

A function returns a value; a procedure does not.

52
New cards

Write Python code to define a function named 'area' taking 2 parameters (length, width).

def area(length, width):

53
New cards

Write Python code to call a procedure named 'ageCheck' taking 1 parameter (21).

ageCheck(21)

54
New cards

Why are global variables generally discouraged?

They can be accessed and modified from anywhere, leading to potential bugs and hard-to-maintain code.

55
New cards

Why is random number generation used in programming?

It adds an element of unpredictability to a program.

56
New cards

True or False? Simulating the roll of a dice is an example of random number generation.

True.

57
New cards

How do you import the random module in Python?

import random

58
New cards

What does random.randint(a, b) do in Python?

Generates a random integer between a and b, inclusive.

59
New cards

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)