An original Thinka practice paper modelled on the structure and difficulty of the Jun 2024 Pearson Edexcel GCSE Computer Science (1CP2) paper. Not affiliated with or reproduced from Pearson.
卷一: Principles of Computer Science
Answer all questions. You are not allowed to use a calculator.
32 題目 · 75.00000000000003 分
題目 1 · 選擇題
1 分
Which network protocol is primarily used by an email client to send an email to a mail server?
A.POP (Post Office Protocol)
B.IMAP (Internet Message Access Protocol)
C.SMTP (Simple Mail Transfer Protocol)
D.HTTP (Hypertext Transfer Protocol)
查看答案詳解收起答案詳解
解題
SMTP (Simple Mail Transfer Protocol) is used to send email from a client to a server, or between email servers. POP and IMAP are used to retrieve email from a server.
評分準則
1 mark for correct option C. Reject any other options.
題目 2 · 選擇題
1 分
An 8-bit binary register contains the value 00111000. Which binary pattern represents the result of applying a logical right shift of two places to this value?
A.11001110
B.00001110
C.11100000
D.00111011
查看答案詳解收起答案詳解
解題
A logical right shift of two places moves all bits two positions to the right, filling the empty positions on the left with 0s: 00111000 shifted right by one is 00011100, and shifted right by two is 00001110.
評分準則
1 mark for correct option B. Reject any other options.
題目 3 · 選擇題
1 分
Utility software is a type of system software. Which one of these is a function of defragmentation utility software?
A.To encrypt data files before they are transmitted over a network.
B.To compress large files into a smaller size to save storage space.
C.To reorganise files on a magnetic hard drive so that parts of the same file are stored in contiguous blocks.
D.To scan the computer system for malware and remove any threats detected.
查看答案詳解收起答案詳解
解題
Defragmentation utility software reorganises a magnetic hard drive by putting the split-up (fragmented) parts of files back together in contiguous blocks. This speeds up read and write times.
評分準則
1 mark for correct option C. Reject any other options.
題目 4 · 選擇題
1 分
An individual intercepts transmission data over a wireless network without permission. Which UK legislation is specifically violated by this unauthorised access to computer material?
A.Data Protection Act 2018
B.Computer Misuse Act 1990
C.Copyright, Designs and Patents Act 1988
D.Freedom of Information Act 2000
查看答案詳解收起答案詳解
解題
The Computer Misuse Act 1990 makes unauthorised access to computer material (such as hacking or intercepting data without authorisation) a criminal offence.
評分準則
1 mark for correct option B. Reject any other options.
題目 5 · Formula Construction
2.24 分
An uncompressed image has a width of \(W\) pixels, a height of \(H\) pixels, and a colour depth of \(C\) bits. Construct a formula to calculate the total file size of this image in bytes.
查看答案詳解收起答案詳解
解題
To find the file size in bits, we multiply the total number of pixels by the colour depth: \(W \times H \times C\). To convert this value into bytes, we divide the result by 8 because there are 8 bits in one byte. Therefore, the completed formula is \(\frac{W \times H \times C}{8}\) or equivalent algebraic variations like \((W \times H \times C) / 8\).
評分準則
1 mark for calculating total bits: \(W \times H \times C\). 1 mark for dividing by 8 to convert to bytes.
題目 6 · Formula Construction
2.24 分
A media file of size \(S\) megabytes (MB) is transmitted across a local area network with an average speed of \(R\) megabits per second (Mbps). Construct a mathematical formula to find the theoretical transmission time in seconds. Assume 1 megabyte is exactly equal to 8 megabits.
查看答案詳解收起答案詳解
解題
To determine transmission time, we need consistent units. Converting the file size \(S\) from megabytes to megabits requires multiplying by 8, giving \(S \times 8\) megabits. To find the duration in seconds, we divide the total megabits by the transmission rate \(R\) megabits per second. The resulting formula is \(\frac{S \times 8}{R}\) or \(\frac{8S}{R}\).
評分準則
1 mark for converting megabytes to megabits: \(S \times 8\). 1 mark for dividing the total megabits by the transmission rate \(R\).
題目 7 · Short Answer
2.24 分
Convert the denary number 141 into an 8-bit binary number, and then convert that binary sequence into its hexadecimal equivalent. State only the final hexadecimal value as your answer.
查看答案詳解收起答案詳解
解題
First, convert 141 to 8-bit binary: 141 can be decomposed as 128 + 8 + 4 + 1. In 8-bit binary, this is 10001101. Second, split the 8-bit binary pattern into two 4-bit nibbles: 1000 and 1101. Convert each nibble into hexadecimal: 1000 in binary is 8 in hex; 1101 in binary is 13 in denary, which corresponds to D in hex. Putting them together gives 8D.
評分準則
1 mark for correct binary representation (10001101). 1 mark for correct final hexadecimal equivalent (8D).
題目 8 · Short Answer
2.24 分
A binary search is conducted on the following sorted list of integers to find the target value 33: [3, 8, 12, 15, 21, 28, 33, 47, 50]. Indices range from 0 to 8. Assuming the midpoint index is calculated using integer division (mid = (low + high) // 2), list the sequence of values that are compared with the target until it is found.
查看答案詳解收起答案詳解
解題
Initial list has indices 0 to 8. Step 1: low = 0, high = 8. mid = (0 + 8) // 2 = 4. The value at index 4 is 21. Since 21 < 33, the search range shifts to indices 5 to 8. Step 2: low = 5, high = 8. mid = (5 + 8) // 2 = 6. The value at index 6 is 33. Since 33 matches our target, the search terminates. The compared values are 21 and then 33.
評分準則
1 mark for identifying the first comparison value as 21. 1 mark for identifying the second comparison value as 33.
題目 9 · Short Answer
2.24 分
Evaluate the arithmetic output of the following programming expression. Show your intermediate working: (23 MOD 5) * (17 DIV 3)
查看答案詳解收起答案詳解
解題
1. Resolve the left side: 23 MOD 5. 23 divided by 5 is 4 with a remainder of 3. So, 23 MOD 5 = 3. 2. Resolve the right side: 17 DIV 3. 17 integer divided by 3 is 5 (since 3 * 5 = 15). So, 17 DIV 3 = 5. 3. Perform the multiplication: 3 * 5 = 15.
評分準則
1 mark for evaluating 23 MOD 5 as 3. 1 mark for evaluating 17 DIV 3 as 5. 1 mark for multiplying the results to arrive at 15.
題目 10 · Short Answer
2.24 分
Explain the primary difference between passing an argument to a subprogram by value and passing it by reference.
查看答案詳解收起答案詳解
解題
When arguments are passed by value, a local copy of the variable's value is created within the subprogram's scope. Any changes made to it are discarded when the subprogram terminates. When passed by reference, the subprogram receives a direct link (address pointer) to the original variable, meaning any adjustments update the actual value in the calling routine.
評分準則
1 mark for explaining that passing by value uses a copy of the data (leaving the original unaffected). 1 mark for explaining that passing by reference uses the memory address (modifying the original variable).
題目 11 · Short Answer
2.24 分
A two-dimensional array named 'matrix' is defined as follows: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Assuming array indices start at 0, write a syntax expression to access the value 6 from this array.
查看答案詳解收起答案詳解
解題
The 2D array contains 3 sub-arrays. The value 6 is located in the second sub-array: [4, 5, 6], which is at row index 1. Within that sub-array, 6 is the third element, which is at column index 2. Therefore, the lookup path is index 1 followed by index 2, written as matrix[1][2].
評分準則
1 mark for referencing row index 1. 1 mark for referencing column index 2 in the format matrix[1][2].
題目 12 · Short Answer
2.24 分
State the difference between how a compiler and an interpreter handle the translation and execution of high-level programming language code.
查看答案詳解收起答案詳解
解題
A compiler reads the whole source code program and outputs an equivalent executable machine code file. This file can then be run independently of the compiler. An interpreter does not create an executable; instead, it reads, translates to machine instructions, and runs each line of code step-by-step.
評分準則
1 mark for identifying that a compiler translates the entire program at once into machine/executable code. 1 mark for identifying that an interpreter translates and executes line-by-line.
題目 13 · Short Answer
2.24 分
A processor performs an arithmetic shift left by 3 places on the 8-bit binary pattern 00010110. State the resulting 8-bit binary pattern.
查看答案詳解收起答案詳解
解題
Shifting the 8-bit binary pattern 00010110 left by 3 places shifts all bits 3 positions to the left, filling the vacated lower-order bits with 0s. 00010110 shifted left by 1 is 00101100. Shifted left by 2 is 01011000. Shifted left by 3 is 10110000. In denary, 22 multiplied by \(2^3\) (8) is 176, which is represented as 10110000 in binary.
評分準則
Award 1 mark for demonstrating a shift left of the bits by 3 places (e.g., intermediate steps or correct shift direction). Award 1.24 marks for the correct final binary string: 10110000.
題目 14 · Short Answer
2.24 分
A 10-second mono audio file is recorded with a sample rate of 44,100 Hz and a bit depth of 16 bits. State the formula, using exact values, to calculate the file size in bytes. Do not calculate the final answer.
查看答案詳解收起答案詳解
解題
To find the file size in bits, multiply the sample rate (44100 Hz), bit depth (16 bits), duration (10 seconds), and number of channels (1 for mono). This gives \(44100 \times 16 \times 10 \times 1\). To convert this value from bits to bytes, divide the total by 8. The final formula is \(\frac{44100 \times 16 \times 10}{8}\).
評分準則
Award 1 mark for multiplying the correct frequency, sample rate, and duration: 44100 * 16 * 10. Award 1.24 marks for dividing the entire expression by 8 to convert the answer into bytes.
題目 15 · Short Answer
2.24 分
State two differences between a Media Access Control (MAC) address and an Internet Protocol (IP) address.
查看答案詳解收起答案詳解
解題
A MAC address is a hardware address permanently burned into the Network Interface Card (NIC) at manufacture, making it static. An IP address is a logical network address assigned to a device by a router or network administrator and can change depending on the network the device is connected to. MAC addresses are used for local routing, whereas IP addresses are used for wide-area routing across networks.
評分準則
Award 1 mark for the first valid difference (e.g., MAC is physical/permanent, IP is logical/dynamic). Award 1.24 marks for the second valid difference (e.g., MAC is used for local routing, IP is used for wide-area network routing).
題目 16 · Short Answer
2.24 分
Explain one advantage of using local variables rather than global variables in subprograms.
查看答案詳解收起答案詳解
解題
Local variables are declared inside a subprogram and are only accessible within that specific subprogram (local scope). This encapsulates the variable and prevents other parts of the program from accidentally reading or changing its value, making debugging, testing, and reusing code much easier.
評分準則
Award 1 mark for identifying an advantage (e.g., encapsulation, preventing variable naming conflicts, saving memory). Award 1.24 marks for explaining how this is beneficial (e.g., makes debugging easier because variables cannot be changed by external code, allows subprograms to be self-contained and easily reused).
題目 17 · Short Answer
2.24 分
An outdoor wildlife camera records video onto an SD card (solid-state) rather than a CD-R (optical). Explain one reason why solid-state storage is more suitable for this device.
查看答案詳解收起答案詳解
解題
Solid-state storage media, such as SD cards, use electronic flash memory and contain no moving parts. This makes them highly robust, durable, and resistant to physical shocks, vibrations, and temperature variations common in outdoor environments. In contrast, optical media like CD-Rs rely on laser assemblies and spinning discs, which are highly susceptible to failing if bumped, shaken, or exposed to weather.
評分準則
Award 1 mark for identifying a relevant property of solid-state storage (e.g., no moving parts, durable, compact physical size). Award 1.24 marks for linking this property to the context of an outdoor camera (e.g., will not fail or skip when shaken by wind or animal activity, fits easily into a weather-sealed camera enclosure).
題目 18 · Short Answer
2.24 分
Describe one benefit of using a compiler instead of an interpreter to translate high-level program code into machine code.
查看答案詳解收起答案詳解
解題
A compiler translates the entire high-level source code at once to produce a standalone executable file. Once compiled, this executable can be run directly by the CPU without the need for the compiler to be present or for line-by-line translation to happen during execution, resulting in faster execution speeds. It also protects the source code from being easily viewed or modified by the end-user.
評分準則
Award 1 mark for identifying a benefit (e.g., faster execution speed at runtime, no need to share the source code, no need for the translator to be present on the target machine). Award 1.24 marks for explaining how this benefit is achieved (e.g., by translating the entire program beforehand into machine code or an executable file).
題目 19 · Short Answer
2.24 分
An ordered list contains the following elements: [3, 8, 12, 15, 21, 28, 32]. State the list of elements that will be compared to the search key 28 during a binary search, in the correct order.
查看答案詳解收起答案詳解
解題
A binary search starts by checking the middle element of the sorted list. The list length is 7, so the middle index is 3 (element 15). Since the target 28 is greater than 15, the search shifts to the right sublist [21, 28, 32] (indices 4 to 6). The midpoint of this sublist is index 5 (element 28). The target matches 28, so the search terminates. The compared elements are 15, then 28.
評分準則
Award 1 mark for identifying 15 as the first element compared. Award 1.24 marks for identifying 28 as the second element compared, in the correct sequence.
題目 20 · Short Answer
2.24 分
Modern data centres consume massive amounts of electricity. Explain one action a data centre company can take to reduce its environmental impact.
查看答案詳解收起答案詳解
解題
Data centres require large amounts of electricity for powering servers and maintaining cooling systems. To reduce their environmental impact, operators can source energy from 100% renewable resources (like wind, solar, or hydroelectric power). Alternatively, they can locate facilities in colder climates to use natural air cooling (free cooling), or use server virtualisation to increase server utilisation and reduce the total number of active physical machines required.
評分準則
Award 1 mark for identifying a valid action (e.g., using renewable energy sources, locating servers in cold climates, using virtualisation to reduce active hardware). Award 1.24 marks for explaining how this action reduces the environmental impact (e.g., reduces carbon emissions, lowers electricity consumption for cooling, reduces physical e-waste and manufacturing footprint).
題目 21 · Short Answer
2.24 分
Express the denary number -43 as an 8-bit two's complement binary integer. Show your working.
查看答案詳解收起答案詳解
解題
Convert the positive equivalent (+43) to 8-bit binary: \(43 = 32 + 8 + 2 + 1 = 00101011_2\). Flip all the bits to get the one's complement: \(11010100\). Add 1 to get the final two's complement representation: \(11010100 + 1 = 11010101\).
評分準則
1 mark for correctly showing the binary conversion of +43 (\(00101011\)) or for demonstrating the bit-flipping step (\(11010100\)). 1.24 marks for the final correct binary representation (\(11010101\)).
題目 22 · Short Answer
2.24 分
A file of size 6 Megabytes (MB) is transmitted over a network at a speed of 16 Megabits per second (Mbps). Calculate the theoretical minimum transmission time in seconds. Show your working.
查看答案詳解收起答案詳解
解題
First, convert the file size from Megabytes to Megabits. Since \(1 \text{ Byte} = 8 \text{ bits}\), \(6 \text{ MB} = 6 \times 8 = 48 \text{ Megabits}\). Next, divide the total size in Megabits by the transmission speed: \(48 \text{ Megabits} / 16 \text{ Mbps} = 3 \text{ seconds}\).
評分準則
1 mark for converting Megabytes to Megabits (\(6 \times 8 = 48\)) or showing the correct formula usage. 1.24 marks for the correct final answer of 3.
題目 23 · Short Answer
2.24 分
State the final value of the variable result after executing the following expression: result = (29 MOD 6) * (14 DIV 3).
查看答案詳解收起答案詳解
解題
First, evaluate the modulo operation: \(29 \text{ MOD } 6 = 5\) because \(29 - (4 \times 6) = 5\). Next, evaluate the integer division: \(14 \text{ DIV } 3 = 4\) because 3 goes into 14 four whole times. Finally, multiply the two results: \(5 \times 4 = 20\).
評分準則
1 mark for showing correct individual evaluations of MOD (\(5\)) and DIV (\(4\)). 1.24 marks for the final correct answer of 20.
題目 24 · Short Answer
2.24 分
An ordered list contains the following 15 elements: [2, 5, 8, 12, 16, 23, 38, 45, 56, 60, 72, 80, 85, 90, 99]. Using a standard binary search algorithm where the midpoint is rounded down (using integer division), state all the elements that will be compared to find the search key 85 in the exact order they are compared.
查看答案詳解收起答案詳解
解題
First comparison: Midpoint of index 0 to 14 is index 7, which is 45. Since \(85 > 45\), search right. Second comparison: Midpoint of index 8 to 14 is index 11, which is 80. Since \(85 > 80\), search right. Third comparison: Midpoint of index 12 to 14 is index 13, which is 90. Since \(85 < 90\), search left. Fourth comparison: Midpoint of index 12 to 12 is index 12, which is 85. Matches search key.
評分準則
1 mark for correctly identifying the first two comparison elements (45 and 80). 1.24 marks for listing all four elements in correct order (45, 80, 90, 85).
題目 25 · Short Answer
2.24 分
A magnetic hard disk drive (HDD) has a total storage capacity of 4 TB. An operating system and essential applications take up 800 GB. If each high-definition movie file is 8 GB in size, calculate the maximum number of movies that can be stored on the remaining space of the HDD. (Assume \(1 \text{ TB} = 1000 \text{ GB}\)).
1 mark for calculating the correct remaining storage capacity of 3200 GB. 1.24 marks for the correct final answer of 400.
題目 26 · Short Answer
2.24 分
An uncompressed image file has a size of 4.5 MB. After applying a lossless compression algorithm, the size of the file is reduced to 1.8 MB. Calculate the compression ratio achieved, expressed as a simplified ratio of the original size to the compressed size in the format X:Y.
查看答案詳解收起答案詳解
解題
The initial ratio of original to compressed size is \(4.5 : 1.8\). Multiply both sides by 10 to clear decimals, giving \(45 : 18\). Divide both terms by their greatest common divisor (9) to simplify: \(45/9 : 18/9 = 5 : 2\).
評分準則
1 mark for setting up the initial ratio \(4.5 : 1.8\) or \(45 : 18\). 1.24 marks for the fully simplified final ratio 5:2.
題目 27 · Short Answer
2.24 分
State the output of the final print statement in this pseudocode: SET globalVar TO 15; FUNCTION modifyValue(num) SET num TO num * 2; RETURN num - 5; ENDFUNCTION; SET result TO modifyValue(globalVar); SEND globalVar TO DISPLAY
查看答案詳解收起答案詳解
解題
The global variable `globalVar` is set to 15. The function `modifyValue` receives the value of `globalVar` (15) as a parameter passed by value. Although the local variable `num` inside the function is modified, the global variable `globalVar` itself is unaffected. Therefore, printing `globalVar` outputs 15.
評分準則
1 mark for demonstrating that the global variable remains unmodified by the function call. 1.24 marks for the final correct output of 15.
題目 28 · Short Answer
2.24 分
Under the UK Data Protection Act 2018, state the specific term used to describe the individual or organization that determines the purposes and means of processing personal data.
查看答案詳解收起答案詳解
解題
The legislation defines a 'Data Controller' as the person or organization who determines the purposes for which and the manner in which any personal data are to be processed.
評分準則
1 mark for identifying the concept of a controller. 1.24 marks for the exact legal term 'Data Controller'.
題目 29 · Short Answer
2.24 分
An uncompressed bitmap image has a width of 1200 pixels and a height of 800 pixels. The image is saved with a colour depth of 16 bits.
Construct an expression to calculate the minimum file size of this image in kibibytes (KiB). You do not need to calculate the final answer.
查看答案詳解收起答案詳解
解題
To find the file size of the image, we use the following steps: 1. Calculate the total number of bits in the image by multiplying the width, height, and colour depth: \(1200 \times 800 \times 16\)
2. Convert the total bits into bytes by dividing by 8: \(\frac{1200 \times 800 \times 16}{8}\)
3. Convert the bytes into kibibytes (KiB) by dividing by 1024: \(\frac{1200 \times 800 \times 16}{8 \times 1024}\) or \(\frac{1200 \times 800 \times 16}{8192}\)
Any equivalent expression is acceptable, such as: - \((1200 \times 800 \times 16) / 8 / 1024\) - \(\frac{1200 \times 800 \times 2}{1024}\) (since \(16 / 8 = 2\))
評分準則
Award 1 mark for calculating the total number of bits: - \(1200 \times 800 \times 16\) (or equivalent)
Award 1 mark for converting bits to KiB by dividing by 8 and 1024 (or 8192): - Division by \(8 \times 1024\) (or division by 8, then division by 1024)
A small accounting firm is planning to replace all 50 of its old office desktop computers with "thin client" terminals that connect to a cloud-hosted server.
Discuss the ethical and environmental impacts of the firm's decision to move to thin clients and cloud-hosted storage.
In your answer, you should consider: - the environmental benefits and drawbacks of cloud servers versus local desktop computers - the ethical implications regarding the disposal of the old hardware and data privacy.
查看答案詳解收起答案詳解
解題
To achieve 5-6 marks, the candidate must provide a balanced discussion covering both ethical and environmental impacts with logical structure:
1. **Environmental Impacts**: - **Benefits**: Thin clients have lower power consumption, generate less heat, and have a longer operational lifespan than traditional PCs. Cloud-hosting providers often have highly efficient, purpose-built data centers (utilizing green energy and advanced cooling) which are more efficient than running 50 independent, power-hungry desktop towers. - **Drawbacks**: Cloud data centers run 24/7 and consume massive amounts of electricity and water for cooling. Manufacturing thin clients still consumes raw materials.
2. **Ethical & Legal Impacts**: - **E-waste disposal**: Disposing of 50 desktop computers contributes to the global e-waste crisis. The firm has an ethical duty to recycle them responsibly (e.g., via WEEE regulations) rather than sending them to landfill or exporting them to developing countries where toxic chemicals (like lead and mercury) pose health risks to local populations. - **Data Privacy & Security**: Moving financial data to a third-party cloud server introduces privacy risks. The firm must ensure the cloud provider complies with the Data Protection Act 2018 / GDPR, securing sensitive client information from data breaches or unauthorized surveillance.
評分準則
**Level 1 (1-2 marks)** - Attempted to identify at least one environmental or ethical issue (e.g., recycling, or power usage). - The answer is likely to be a list of points or a very brief description without expansion. - There is little or no structure.
**Level 2 (3-4 marks)** - Identifies both environmental and ethical issues, with some explanation of at least one. - Demonstrates an understanding of how cloud computing affects energy use or how e-waste affects the environment/health. - The response is structured and mostly coherent.
**Level 3 (5-6 marks)** - Provides a balanced and detailed discussion of both environmental impacts (energy saving of thin clients vs data center power consumption) and ethical/legal impacts (proper e-waste recycling, third-party data privacy). - Points are well-developed, linked, and show depth of understanding. - The response is logically structured and uses appropriate technical terminology.
題目 31 · Flowchart / Diagram Construction
4.5 分
An algorithm is designed to calculate the average of positive numbers. A flowchart for this algorithm has four missing boxes: Box A, Box B, Box C, and Box D.
- Box A is an initialization process box at the start. - Box B is a decision box checking for the terminating condition (a negative number entered by the user). - Box C is a process box to update the running total. - Box D is a process box to update the count of numbers.
State the exact statements or conditions that should be placed inside Box A, Box B, Box C, and Box D to ensure the flowchart operates correctly.
查看答案詳解收起答案詳解
解題
To construct this flowchart correctly: 1. Box A (Initialization): Before entering the loop, the accumulator variables must be set to 0. Thus, total = 0 and count = 0. 2. Box B (Decision): The loop terminates when a negative number is entered. Therefore, the condition to branch to the termination/average calculation path is num < 0 (assuming 'Yes' leads to termination). 3. Box C (Running Total): The current number must be added to the running total. Thus, total = total + num. 4. Box D (Counter): The counter must increment by 1 to track how many positive numbers have been entered. Thus, count = count + 1.
評分準則
Award up to 4.5 marks as follows: - 1 mark for Box A: Correctly initializing both total and count to 0 (e.g., 'total = 0, count = 0' or equivalent separate statements). - 1 mark for Box B: Correctly stating the decision condition (accept 'num < 0' or 'num is negative'). - 1 mark for Box C: Correctly updating the running total (accept 'total = total + num' or 'total += num'). - 1 mark for Box D: Correctly incrementing the counter (accept 'count = count + 1' or 'count += 1'). - 0.5 marks: Consistently using the same variable names across all boxes (accuracy/consistency mark).
題目 32 · Flowchart / Diagram Construction
4.5 分
A flowchart controls an automated greenhouse window using two inputs: temperature (stored in variable T) and humidity (stored in variable H).
- If T is greater than 25 and H is greater than 60, the window is opened (outputs 'OPEN'). - Otherwise, if T is less than 18, the window is closed (outputs 'CLOSE'). - In all other cases, the window remains in its current state (no action/outputs 'KEEP').
The flowchart has four blank components: - Box P (Decision shape) - Box Q (Output shape if Box P is True) - Box R (Decision shape if Box P is False) - Box S (Output shape if Box R is True)
Identify the exact conditions or outputs that must be placed inside Box P, Box Q, Box R, and Box S.
查看答案詳解收起答案詳解
解題
Following the logic rules of the greenhouse control system: - Box P: Must represent the first compound condition. T must be greater than 25 and H must be greater than 60, written as T > 25 AND H > 60. - Box Q: Is the consequence of Box P being True, which is to open the window. Thus, the output is 'OPEN'. - Box R: Is the secondary decision evaluated if the first condition is False. It checks if T is less than 18, written as T < 18. - Box S: Is the consequence of Box R being True, which is to close the window. Thus, the output is 'CLOSE'.
評分準則
Award up to 4.5 marks as follows: - 1.5 marks for Box P: Correctly identifying the compound condition 'T > 18' (0.5 marks for T > 25, 0.5 marks for H > 60, and 0.5 marks for logical AND connector). - 1 mark for Box Q: Correctly identifying output as 'OPEN' or 'Open window'. - 1 mark for Box R: Correctly identifying the condition 'T < 18'. - 1 mark for Box S: Correctly identifying output as 'CLOSE' or 'Close window'.
卷二: Application of Computational Thinking
Answer all questions on your computer workstation. Save your work regularly.
6 題目 · 75 分
題目 1 · Code Correction (Debugging)
10 分
A programmer is writing a Python program to process student exam results.
The function `calculate_passing_average(student_data)` is designed to accept a list of student dictionaries, filter out any students who did not pass, and print the average score of those who did pass.
A passing score is defined as **50 or above**. If no students passed, the program should print `"No students passed."`.
The programmer's initial attempt contains five distinct errors.
Review the buggy code below:
```python def calculate_passing_average(student_data): total_score = "0" count = 0 for student in student_data: score = student["score"] if score > 50: total_score =+ score count += 1
if count = 0: print("No students passed.") else: average = total_score / count print("The average passing score is: " + average) ```
Correct the code so that it functions as specified and contains no errors. You must write out the fully corrected code.
查看答案詳解收起答案詳解
解題
To correct the code, the following five errors must be resolved:
1. **Incorrect Initialization Type (Line 2):** `total_score` is initialized as a string (`"0"`). This must be initialized as an integer (`0`) to allow mathematical addition. *Correction:* `total_score = 0`
2. **Incorrect Comparison Operator for Pass Condition (Line 6):** The check `if score > 50` excludes students who scored exactly 50. Since a pass is 50 or above, it must use `>=`. *Correction:* `if score >= 50:`
3. **Incorrect Assignment/Accumulation Operator (Line 7):** `total_score =+ score` acts as a positive unary assignment (equivalent to `total_score = (+score)`), which overwrites the total rather than adding to it. It must be `+=` to accumulate. *Correction:* `total_score += score` (or `total_score = total_score + score`)
4. **Syntax Error in Conditional Statement (Line 10):** `if count = 0:` uses the single equals assignment operator instead of the double equals comparison operator. *Correction:* `if count == 0:`
5. **TypeError in Print Concatenation (Line 14):** `print("The average passing score is: " + average)` tries to concatenate a string and a float. The float variable `average` must be explicitly converted to a string, or formatted printing (f-string) must be used. *Correction:* `print("The average passing score is: " + str(average))` or `print(f"The average passing score is: {average}")`
評分準則
Award up to 10 marks for correcting the five errors (2 marks per corrected error):
* **Error 1: String initialization** * **1 mark** for identifying that `total_score = "0"` is an incorrect data type. * **1 mark** for correcting to `total_score = 0` (accept `0.0`).
* **Error 2: Pass condition boundary check** * **1 mark** for identifying that `> 50` does not include 50. * **1 mark** for correcting to `>= 50`.
* **Error 3: Accumulator operator syntax/logic** * **1 mark** for identifying that `=+` does not accumulate. * **1 mark** for correcting to `+=` (or equivalent: `total_score = total_score + score`).
* **Error 4: Comparison operator syntax** * **1 mark** for identifying that `=` is used for assignment instead of comparison. * **1 mark** for correcting to `==` (or equivalent logical check, such as `if not count:`).
* **Error 5: Type mismatch during concatenation** * **1 mark** for identifying that a string cannot be concatenated with a float/number directly. * **1 mark** for correcting to convert `average` to a string using `str(average)` or formatting via an f-string.
題目 2 · practical
10 分
An analyst is developing a Python subprogram to encrypt messages using a Caesar cipher. The function `encrypt_caesar(plaintext, shift)` takes a string parameter representing the message to encrypt, and an integer parameter representing the key (shift).
The function must: 1. Loop through each character of the `plaintext` input. 2. If the character is an uppercase letter (A-Z), shift it by the key value, wrapping around the alphabet if necessary. 3. Keep non-uppercase characters (such as spaces or punctuation) unchanged. 4. Build and return the encrypted `ciphertext` string.
Here is the incomplete Python code with five missing segments labeled **GAP 1** to **GAP 5**:
```python def encrypt_caesar(plaintext, shift): ciphertext = "" for char in plaintext: if char.isupper(): # GAP 1 ... # GAP 2 ... # GAP 3 ... # GAP 4 ... else: # GAP 5 ... return ciphertext ```
Study the tables below and select the correct option code for each gap.
### **GAP 1 Options (Find ASCII value of the character)** * **A1**: `char_code = chr(char)` * **A2**: `char_code = ord(char)` * **A3**: `char_code = ascii(char)`
Write down your final choices for GAP 1 to GAP 5 using their corresponding identifiers.
查看答案詳解收起答案詳解
解題
Let us trace the correct choices to complete the Caesar cipher algorithm in Python:
1. **GAP 1**: To convert a single character string into its integer ASCII representation, Python uses the built-in function `ord()`. Thus, `char_code = ord(char)` is correct (**A2**). `chr()` does the opposite (integer to string), and `ascii()` returns a printable representation of an object. 2. **GAP 2**: To implement alphabet wrap-around easily, we map 'A' (ASCII 65) to 0. Subtracting 65 from our code and then adding the shift value yields `char_code - 65 + shift`. Thus, `shifted_code = char_code - 65 + shift` is correct (**B1**). 3. **GAP 3**: After applying modulo 26 to wrap around the alphabet \((0-25)\), we must add back the ASCII value of 'A' (65) to restore it to the correct uppercase character block. Thus, `wrapped_code = (shifted_code % 26) + 65` is correct (**C1**). 4. **GAP 4**: We need to convert the numeric ASCII code (`wrapped_code`) back into a character using `chr()` and concatenate it to our accumulated `ciphertext` string. Thus, `ciphertext = ciphertext + chr(wrapped_code)` is correct (**D2**). 5. **GAP 5**: Any non-uppercase characters must remain unchanged and be appended to the output string. Thus, we concatenate the raw character `char` to `ciphertext`. Hence, `ciphertext = ciphertext + char` is correct (**E1**).
評分準則
Award 2 marks for each correct code selection: * **GAP 1**: Award 2 marks for **A2**. (Award 0 marks for A1 or A3). * **GAP 2**: Award 2 marks for **B1**. (Award 0 marks for B2 or B3). * **GAP 3**: Award 2 marks for **C1**. (Award 0 marks for C2 or C3). * **GAP 4**: Award 2 marks for **D2**. (Award 0 marks for D1 or D3). * **GAP 5**: Award 2 marks for **E1**. (Award 0 marks for E2 or E3).
題目 3 · Logic and Sequence Completion
10 分
An analyst is designing and testing algorithms that process sequences of numbers.
### Part A (6 marks)
A Python function `generate_sequence` is defined below. It takes two integer parameters, `start` and `limit`, and returns a list containing a generated sequence.
```python def generate_sequence(start, limit): seq = [] current = start while current < limit and len(seq) < 6: if current % 2 == 0: current = (current // 2) + 3 else: current = (current * 3) - 1 seq.append(current) return seq ```
Complete the trace table for the function call `generate_sequence(4, 50)`.
Identify the missing code required to complete the functions below.
**(i)** The function `construct_sequence(n)` should generate a sequence containing the first `n` terms of the geometric sequence: \(1, -2, 4, -8, 16, -32, \dots\)
Complete line 6 with an expression to update the value of `term`.
```python def construct_sequence(n): seq = [] term = 1 for i in range(n): seq.append(term) term = ________(i)________ return seq ```
**(ii)** The function `alternating_sum(numbers)` should sum all elements in a list, but alternate between adding and subtracting elements based on whether their index is even or odd (e.g. `alternating_sum([10, 2, 5, 3])` returns \(10 - 2 + 5 - 3 = 10\)).
Complete line 5 with a logical condition to check if the current index `i` is even.
```python def alternating_sum(numbers): total = 0 for i in range(len(numbers)): if ________(ii)________: total = total + numbers[i] else: total = total - numbers[i] return total ```
查看答案詳解收起答案詳解
解題
### Part A Solution: We trace the function execution with `start = 4` and `limit = 50`: - **Initial State**: `current` starts at `4`, and `seq` starts as `[]`. - **Iteration 1**: At the loop start, `current < 50` is `True` and `len(seq) < 6` (0 < 6) is `True`. Since `current` (4) is even, `current = (4 // 2) + 3 = 5`. `seq` becomes `[5]`. - **Iteration 2**: `current` (5) is `< 50` (`True`) and `len(seq)` (1) is `< 6` (`True`). Since 5 is odd, `current = (5 * 3) - 1 = 14`. `seq` becomes `[5, 14]`. - **Iteration 3**: `current` (14) is `< 50` (`True`) and `len(seq)` (2) is `< 6` (`True`). Since 14 is even, `current = (14 // 2) + 3 = 10`. `seq` becomes `[5, 14, 10]`. - **Iteration 4**: `current` (10) is `< 50` (`True`) and `len(seq)` (3) is `< 6` (`True`). Since 10 is even, `current = (10 // 2) + 3 = 8`. `seq` becomes `[5, 14, 10, 8]`. - **Iteration 5**: `current` (8) is `< 50` (`True`) and `len(seq)` (4) is `< 6` (`True`). Since 8 is even, `current = (8 // 2) + 3 = 7`. `seq` becomes `[5, 14, 10, 8, 7]`. - **Iteration 6**: `current` (7) is `< 50` (`True`) and `len(seq)` (5) is `< 6` (`True`). Since 7 is odd, `current = (7 * 3) - 1 = 20`. `seq` becomes `[5, 14, 10, 8, 7, 20]`. - **Final Loop Check**: `current` is `20` (which is `< 50`, `True`), but `len(seq)` is `6` (so `len(seq) < 6` is `False`). The loop terminates because both conditions of the logical `and` must be `True`.
### Part B Solution: **(i)** To generate the geometric sequence where each term multiplies by \(-2\), we must set `term` to `term * -2` on each iteration. Correct answer: `term * -2` (or equivalent). **(ii)** To check if index `i` is even, we use the modulo operator `%` to see if the remainder when dividing by 2 is 0. Correct answer: `i % 2 == 0` (or equivalent).
評分準則
### Part A [6 Marks] - **1 mark** for starting with correct initial values and correctly evaluating the loop conditions `True` and `True` on iteration 1. - **1 mark** for correctly applying the even condition logic (`(current // 2) + 3`) on iterations 1, 3, 4, 5. - **1 mark** for correctly applying the odd condition logic (`(current * 3) - 1`) on iterations 2 and 6. - **1 mark** for tracking all consecutive updates of `current` precisely (`5`, `14`, `10`, `8`, `7`, `20`). - **1 mark** for maintaining the list `seq` correctly containing the appended items sequentially across all steps. - **1 mark** for writing the final evaluation row showing `len(seq) < 6` evaluates to `False`, leading to the correct loop exit.
### Part B [4 Marks] - **(i) [2 marks]**: - **2 marks** for `term * -2` (or `term * (-2)`, or `-2 * term`). - **1 mark** for a partially correct answer (e.g., using `* 2` or multiplying without referencing `term`). - **(ii) [2 marks]**: - **2 marks** for `i % 2 == 0` (or equivalent like `i % 2 != 1` or `(i % 2) == 0`). - **1 mark** for identifying `% 2` but incorrect syntax or comparison.
題目 4 · Algorithmic Translation
15 分
An algorithm is represented by the following flowchart description. Write a Python program that implements this algorithm.
### Flowchart Description * **Start** * **Input**: Ask the user to enter their order total. Store this real number in a variable named `order_total`. * **Input**: Ask the user if they have a loyalty card. Store this string in a variable named `loyalty`. * **Decision**: Test if `loyalty` is equal to `"Y"` OR `loyalty` is equal to `"N"`. * **If NO**: * **Output**: `"Error: Invalid loyalty choice"` * **Stop** (The program must stop and not perform any further calculations). * **If YES**: * **Decision**: Test if `loyalty` is equal to `"Y"`. * **If YES**: * **Decision**: Test if `order_total` is greater than or equal to `100.0`. * **If YES**: Set `discount_rate` to `0.15`. * **If NO**: Set `discount_rate` to `0.10`. * **If NO**: * **Decision**: Test if `order_total` is greater than or equal to `100.0`. * **If YES**: Set `discount_rate` to `0.05`. * **If NO**: Set `discount_rate` to `0.0`. * **Process**: Calculate `discount_amount` as `order_total * discount_rate`. * **Process**: Calculate `final_price` as `order_total - discount_amount`. * **Output**: Display `"Final price is: "` followed by the calculated `final_price`. * **Stop**
### Requirements 1. Use Python to write the program. 2. Ensure you use the exact variable names specified: `order_total`, `loyalty`, `discount_rate`, `discount_amount`, and `final_price`. 3. Your inputs and outputs must match the requirements of the flowchart description exactly.
查看答案詳解收起答案詳解
解題
A complete and correct Python program implementation is:
```python order_total = float(input("Enter order total: ")) loyalty = input("Do you have a loyalty card? (Y/N): ")
if loyalty != "Y" and loyalty != "N": print("Error: Invalid loyalty choice") else: if loyalty == "Y": if order_total >= 100.0: discount_rate = 0.15 else: discount_rate = 0.10 else: if order_total >= 100.0: discount_rate = 0.05 else: discount_rate = 0.0
* **Input & Data Casting (2 Marks)** * **[1 Mark]** Correctly prompting for and reading `order_total`, cast to a floating-point/real data type. * **[1 Mark]** Correctly prompting for and reading `loyalty` as a string.
* **Validation Logic (3 Marks)** * **[1 Mark]** Logical condition checking if `loyalty` is not equal to `"Y"` AND not equal to `"N"` (or equivalent structure). * **[1 Mark]** Outputting the exact string `"Error: Invalid loyalty choice"` when validation fails. * **[1 Mark]** Controlling execution flow so that calculation steps do NOT execute when input is invalid (e.g., using an `if/else` structure or program exit).
* **Loyalty Discount Logic ('Y') (3 Marks)** * **[1 Mark]** Correct outer conditional structure checking if `loyalty` is equal to `"Y"`. * **[1 Mark]** Correct inner check comparing `order_total >= 100.0`. * **[1 Mark]** Correctly assigning `discount_rate` to `0.15` (if true) and `0.10` (if false).
* **Non-Loyalty Discount Logic ('N') (3 Marks)** * **[1 Mark]** Correct conditional branch handling when `loyalty` is equal to `"N"`. * **[1 Mark]** Correct inner check comparing `order_total >= 100.0`. * **[1 Mark]** Correctly assigning `discount_rate` to `0.05` (if true) and `0.0` (if false).
* **Calculation (2 Marks)** * **[1 Mark]** Correct calculation of `discount_amount` as `order_total * discount_rate`. * **[1 Mark]** Correct calculation of `final_price` as `order_total - discount_amount`.
* **Output (2 Marks)** * **[1 Mark]** Outputting the exact string prefix `"Final price is: "`. * **[1 Mark]** Correctly displaying the calculated `final_price` value alongside the label.
題目 5 · practical
15 分
A programmer is developing a tournament tracking system for a school's annual sports day. They need to manage team names and their respective scores.
Write a Python program that meets the following requirements: 1. Create a 1D list called `houses` containing the strings: "Red", "Blue", "Green", "Yellow". 2. Create a 1D list called `points` containing the integers: 120, 95, 150, 110 (in the same order as the houses). 3. Define a function called `find_highest` that takes two parameters (representing the lists of houses and points). The function must: - Use a loop to find the house with the highest score. - Return both the name of the house and its score. 4. Define a procedure called `add_points` that takes four parameters: the list of houses, the list of points, a target house name (string), and additional points (integer). The procedure must: - Perform a linear search to find the target house name in the houses list. - If the house is found, add the additional points to its score in the points list. - If the house is not found, print the message "House not found". 5. In the main part of the program: - Call the `add_points` procedure to add 25 points to "Green". - Call the `find_highest` function to get the winning house and its points. - Print the winning house and its score in the exact format: "Winner: [House] with [Points] points."
查看答案詳解收起答案詳解
解題
The correct solution involves defining two subprograms and then calling them sequentially in the main body.
2. The Function `find_highest`: - Needs a tracker for maximum value and its associated index (or tracking the maximum score and maximum house name directly). - Must iterate through the length of the lists. - Returns two values.
3. The Procedure `add_points`: - Uses a loop to check each element in `house_list`. - Checks if it matches `house_name`. - If matched, adds `score_to_add` to `point_list` at the same index and updates a boolean flag `found = True`. - Prints "House not found" if the loop finishes and `found` remains `False`.
4. Main Calls: - `add_points(houses, points, "Green", 25)` correctly updates Green's score from 150 to 175. - `winner_house, winner_points = find_highest(houses, points)` returns `"Green"` and `175`. - Printing outputs "Winner: Green with 175 points."
評分準則
Max 15 marks:
- **Lists initialization [2 marks]** - 1 mark: Initializing the list `houses` correctly containing all four strings. - 1 mark: Initializing the list `points` correctly containing all four integers in corresponding order.
- **Defining `find_highest` [5 marks]** - 1 mark: Correct function header with two parameters. - 1 mark: Initializing tracker variables with the first index of lists (e.g. `highest_score = point_list[0]`). - 2 marks: Correct loop (e.g. `for i in range(len(point_list))`) and conditional check to find the maximum score. - 1 mark: Returning both the house name and score (e.g., `return highest_house, highest_score`).
- **Defining `add_points` [5 marks]** - 1 mark: Correct procedure header with four parameters. - 2 marks: Correct loop structure to search the `house_list` for the target `house_name`. - 1 mark: Updating the value in `point_list` at the matching index (e.g., `point_list[i] += score_to_add`). - 1 mark: Correct logic to print "House not found" only if the house name is not in the list.
- **Main Program Execution [3 marks]** - 1 mark: Calling `add_points` with correct argument values: `houses, points, "Green", 25`. - 1 mark: Calling `find_highest` with arguments and storing/unpacking the returned values. - 1 mark: Correctly outputting the result using the format: "Winner: [House] with [Points] points." (Accept string concatenation or f-strings).
題目 6 · practical
15 分
A school sports department has a text file named results.txt containing student athletic performances. Each line of the file contains the following data fields separated by commas:
Name, Event, Time
For example: Alice,100m,12.5 Bob,200m,24.1
Write a Python program to process this file. Your program must perform the following actions: 1. Read the records from results.txt. 2. Validate each record according to these rules: - Name must not be blank. - Event must be exactly '100m', '200m', or '400m'. - Time must be a positive float value greater than 0.0. 3. Keep a count of all invalid records encountered. 4. Write all valid records to a new file named clean_results.txt in the same format (comma-separated). 5. Identify the student with the fastest (lowest) time in the '100m' event from the valid records. 6. Display the total number of invalid records discarded. 7. Display the name and time of the fastest '100m' runner.
查看答案詳解收起答案詳解
解題
An example solution in Python:
try: infile = open(\"results.txt\", \"r\") outfile = open(\"clean_results.txt\", \"w\") except FileNotFoundError: print(\"Error: The input file results.txt was not found.\") exit()
invalid_count = 0 fastest_100m_name = \"\" fastest_100m_time = 9999.0 # High initial value for finding minimum
for line in infile: line = line.strip() if not line: continue parts = line.split(\",\")
if len(parts) != 3: invalid_count += 1 continue
name = parts[0].strip() event = parts[1].strip() time_str = parts[2].strip()
# Validation is_valid = True
if name == \"\": is_valid = False
if event not in [\"100m\", \"200m\", \"400m\"]: is_valid = False
if is_valid: # Write to clean file outfile.write(f\"{name},{event},{time_val}\ \")
# Process fastest 100m runner if event == \"100m\": if time_val < fastest_100m_time: fastest_100m_time = time_val fastest_100m_name = name else: invalid_count += 1
infile.close() outfile.close()
print(f\"Total invalid records discarded: {invalid_count}\") if fastest_100m_name != \"\": print(f\"Fastest 100m runner: {fastest_100m_name} with a time of {fastest_100m_time}s\") else: print(\"No valid 100m records found.\")
評分準則
Marks are awarded as follows:
**File operations (2 Marks):** - 1 mark: Correctly opens results.txt for reading ('r') and clean_results.txt for writing ('w'). - 1 mark: Correctly closes both files using .close() (or handles via a 'with' context manager).
**Iteration & Splitting (2 Marks):** - 1 mark: Iterates through each line in the input file and strips leading/trailing whitespaces. - 1 mark: Correctly splits each record by comma (',') delimiter and ensures 3 components exist.
**Validation Logic (4 Marks):** - 1 mark: Correctly checks that the Name is not empty. - 1 mark: Correctly checks that the Event is one of the three allowed values ('100m', '200m', '400m'). - 1 mark: Correctly converts Time to float and checks that it is greater than 0.0 (using try/except to handle conversion exceptions). - 1 mark: Increments an invalid record counter whenever any of the validation conditions fail.
**Tracking the Winner (3 Marks):** - 1 mark: Initializes a tracking variable for fastest time to a high initial value. - 1 mark: Correctly filters calculations to only process records where the event is '100m'. - 1 mark: Correctly compares current time to the minimum tracked, updating the winner name and time variables accordingly.
**File Writing (2 Marks):** - 1 mark: Only writes verified valid records to clean_results.txt. - 1 mark: Correctly formats the written string with comma delimiters and appends a newline character.
**Outputs (2 Marks):** - 1 mark: Prints the correct number of invalid records. - 1 mark: Prints the correct name and time of the fastest 100m runner (or reports none found).
想知道自己有幾分把握?
Thinka 是 DSE 學生用的 AI 練習應用程式,有無限量練習題、即時自動批改和詳細解題步驟。逾 100,000 名學生用它確認自己真的識,而不只是「以為識」。