additional programming techniques
使用闪卡高效复习COMPUTER-SCIENCE科目知识点
共计闪卡
60张
8 programming fundamentals
闪卡自测
String manipulation
所有闪卡
闪卡 1
问题
String manipulation
查看答案
答案
String manipulation is the use of programming techniques to modify, analyse or extract information from a string.
闪卡 2
问题
Case conversion
查看答案
答案
Case conversion is the ability to change a string from one case to another, e.g. lowercase to uppercase.
闪卡 3
问题
Length (string manipulation)
查看答案
答案
Finding the length refers to the ability to count the number of characters in a string.
闪卡 4
问题
Substring
查看答案
答案
A substring is the ability to extract a sequence of characters from a larger string using slicing.
闪卡 5
问题
Concatenation
查看答案
答案
Concatenation is the ability to join two or more strings together to form a single string using the + operator.
闪卡 6
问题
ASCII conversion
查看答案
答案
ASCII conversion is the ability to return an ASCII character from a numerical value and vice versa.
闪卡 7
问题
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
问题
name = "sarah" Write Python code to output the variable name in uppercase.
查看答案
答案
print(name.upper())
闪卡 9
问题
password = "letmein" Write Python code to output the length of the variable "password".
查看答案
答案
print(len(password))
闪卡 10
问题
FName = "Save"SName = "MyExams" Write Python code to output the two variables joined together (concatenation).
查看答案
答案
print(FName + SName)
闪卡 11
问题
File handling
查看答案
答案
File handling is the use of programming techniques to work with information stored in text files.
闪卡 12
问题
Write Python code to open a text file named "fruit.txt" in read only mode.
查看答案
答案
file = open("fruit.txt", "r")
闪卡 13
问题
Write Python code to close a text file.
查看答案
答案
file.close()
闪卡 14
问题
Write Python code to read a line in a text file.
查看答案
答案
file.readline()
闪卡 15
问题
Write Python code to write the value "Oranges" to an open text file
查看答案
答案
file.write("Oranges")
闪卡 16
问题
What does "r" mode do when opening a file?
查看答案
答案
The "r" mode is used for opening a file in read-only mode.
闪卡 17
问题
What does "w" mode do when opening a file?
查看答案
答案
The "w" mode is used for opening a file in write mode, creating a new file if it doesn't exist, or overwriting an existing file.
闪卡 18
问题
What does "a" mode do when opening a file?
查看答案
答案
The "a" mode is used for opening a file in append mode, writing to the end of an existing file.
闪卡 19
问题
True or False? It's important to make a backup of text files before working with them.
查看答案
答案
True. It's important to make a backup of text files before working with them, as mistakes can lead to data loss.
闪卡 20
问题
Database
查看答案
答案
A database is an organised collection of data that allows easy storage, retrieval, and management of information.
闪卡 21
问题
Field
查看答案
答案
A field is one piece of information relating to one person, item or object, represented as a column in a database.
闪卡 22
问题
Record
查看答案
答案
A record is a collection of fields relating to one person, item or object, represented as a row in a database.
闪卡 23
问题
Array (storing data)
查看答案
答案
Useful when working with small amounts of data, stored in main memory (RAM).
闪卡 24
问题
What is an advantage of using a database?
查看答案
答案
Advantages of databases include:
闪卡 25
问题
What is a disadvantage of using text files for data storage?
查看答案
答案
A disadvantage of text files is that it can be difficult to know where one record begins and ends.
闪卡 26
问题
What is an advantage of using arrays for data storage?
查看答案
答案
An advantage of arrays is that they can be more efficient and faster to search than text files.
闪卡 27
问题
When are text files useful for data storage?
查看答案
答案
Text files are useful for storing small amounts of data on secondary storage when the application is closed.
闪卡 28
问题
SQL
查看答案
答案
SQL (Structured Query Language) is a programming language used to interact with a Database Management System (DBMS).
闪卡 29
问题
SELECT (SQL)
查看答案
答案
The SELECT command in SQL is used to retrieve data (fields) from a database table. E.g. SELECT name, age
闪卡 30
问题
FROM (SQL)
查看答案
答案
The FROM command in SQL specifies the table(s) to retrieve data from.
闪卡 31
问题
WHERE (SQL)
查看答案
答案
The WHERE command in SQL filters the data based on a specified condition.
闪卡 32
问题
True or False? The '*' symbol is a wildcard in SQL.
查看答案
答案
True. The * symbol is called a wildcard in SQL and selects all fields in a table when used with SELECT.
闪卡 33
问题
SELECT * FROM Customers; What does this SQL command do?
查看答案
答案
This command selects all fields from the Customers table.
闪卡 34
问题
SELECT name, age FROM Customers WHERE age > 30; What does this SQL command do?
查看答案
答案
This command selects the name and age fields from the Customers table where the age is greater than 30.
闪卡 35
问题
True or False? To select all fields, you must list each field name after SELECT
查看答案
答案
False. Using SELECT * will select all fields in the table.
闪卡 36
问题
Give an example SQL command to select specific fields (country, population) from a table (world) with a condition (only countries that have a population less than 100,000.
查看答案
答案
Example: SELECT country, population FROM world WHERE population < 100000;
闪卡 37
问题
What does the FROM clause specify in an SQL SELECT statement?
查看答案
答案
The FROM clause specifies the table(s) to retrieve data from.
闪卡 38
问题
1D array
查看答案
答案
A 1D array is an ordered, static set of elements that can only store one data type. For example, a row in a table
闪卡 39
问题
2D array
查看答案
答案
A 2D array is an ordered, static set of elements that can only store one data type BUT adds another dimension. It can be visualised as a table with rows and columns.
闪卡 40
问题
Write Python code to create a 1D array named 'temp' with numbers 1-5.
查看答案
答案
temp = [1, 2, 3, 4, 5]
闪卡 41
问题
Write Python code to output element 2 of a 1D array named 'countries'.
查看答案
答案
print(countries[1])
闪卡 42
问题
Write Python code to modify element 3 in a 1D array named 'students' with the value "Rebecca".
查看答案
答案
students[2] = "Rebecca"
闪卡 43
问题
Write Python code to create a 2D array named 'scores'. Use values 1-9 to create 3 rows and 3 columns.
查看答案
答案
scores = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
闪卡 44
问题
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.
闪卡 45
问题
What does zero-indexing mean for arrays?
查看答案
答案
Zero-indexing means that the indexes of an array start from 0, not 1.
闪卡 46
问题
Function
查看答案
答案
A function is a type of sub-program that performs a specific task and returns a value.
闪卡 47
问题
Procedure
查看答案
答案
A procedure is a type of sub-program that performs a specific task but does not return a value.
闪卡 48
问题
Parameter
查看答案
答案
A parameter is a value that is passed into a sub-program (function or procedure).
闪卡 49
问题
True or False? To use a function/procedure it must be 'called'.
查看答案
答案
True. To use a function or procedure, you 'call' it from the main program.
闪卡 50
问题
Global variable
查看答案
答案
A global variable is a variable declared at the outermost level of a program and can be accessed from any part of the program.
闪卡 51
问题
Local variable
查看答案
答案
A local variable is a variable declared within a specific scope, such as a function or code block, and can only be accessed within that scope.
闪卡 52
问题
What is the key difference between a function and a procedure?
查看答案
答案
A function returns a value, whereas a procedure does not return a value.
闪卡 53
问题
Write Python code to define a function named 'area' taking 2 parameters (length, width).
查看答案
答案
def area(length, width):
闪卡 54
问题
Write Python code to call a procedure named 'ageCheck', taking 1 parameter (21).
查看答案
答案
ageCheck(21)
闪卡 55
问题
Why are global variables generally discouraged in programming?
查看答案
答案
Global variables are generally discouraged because they can be accessed and modified from anywhere in the program, leading to potential bugs and hard-to-maintain code.
闪卡 56
问题
Why is random number generation used in programming?
查看答案
答案
Random number generation adds an element of unpredictability to a program.
闪卡 57
问题
True of False? Simulating the roll of a dice is an example of random number generation.
查看答案
答案
True. Examples include simulating dice rolls, selecting random questions, national lottery, cryptography.
闪卡 58
问题
How do you import the random module in Python?
查看答案
答案
To import the random module in Python, use: import random
闪卡 59
问题
random.randint(a, b)
查看答案
答案
The random.randint(a, b) function in Python generates a random integer between a and b, inclusive.
闪卡 60
问题
Write Python code to generate a random colour from 'red, 'blue', 'green' and 'yellow. Output the randomly chosen value.
查看答案
答案
import random colours = ["Red", "Green", "Blue", "Yellow"] random_colour = random.choice(colours) print(random_colour)