A programmer is checking if an input string code has a length of exactly 5 characters and contains only digits. Which validation technique is primarily being used for the length check?
GCE O-Level · Computing (7155)
Testing and Debugging:练习题
5 道选择题即时批改,另有 5 道文字题附完整解题步骤,全部围绕「Testing and Debugging」。
A data validation routine checks if a value \(Y\) (Year of Birth) is within the valid range \(1900 \le Y \le 2024\). To perform boundary value analysis, which of the following sets of test data should be used to test the limits of this range check?
A programmer writes a script to calculate the square root of a user-provided number using math.sqrt(). If the user enters a negative number, the program immediately stops and displays a "ValueError". Which type of error does this represent?
Study the following Python code segment:
total = 0
for i in range(5):
if i % 2 == 0:
total = total + i
What is the final value of total after the loop finishes?
Consider the following Python code intended to sum all odd integers in the list vals = [1, 2, 3, 4, 5]:
total = 0
i = 0
while i <= len(vals):
if vals[i] % 2 != 0:
total += vals[i]
i += 1
What will happen when this code is executed?
A programmer performs a manual dry run of the following algorithm using a trace table:
1. Set \(x = 10\)
2. For each \(i\) in the range from \(1\) to \(3\) (inclusive):
a. \(x = x + i\)
What is the final value of \(x\) recorded in the trace table after the loop finishes?
先自己写一遍答案,再对照解题步骤。
A program is designed to validate a date string in the format "DD-MM". Describe how the program should sequentially use a length check, a format check, and range checks to ensure that a user input like "32-01" is rejected. Specify what each check would look for in this specific input.
先自己写一遍答案,再对照解题步骤。
A system requires a product code to follow the format of exactly three uppercase letters followed by exactly three digits (e.g., \(ABC123\)). A user enters \(AB1234\). Name two specific types of data validation checks that would detect this error and explain how each check would identify the mismatch.
先自己写一遍答案,再对照解题步骤。
A software developer is designing a validation routine for a new user account. The username must satisfy the following conditions: it must not be left blank, it must be between \(5\) and \(12\) characters long, and it must contain only alphanumeric characters.
(a) Identify the three specific types of data validation checks being used to enforce these conditions.
(b) For the length requirement (between \(5\) and \(12\) characters), provide one example of boundary test data and one example of invalid (error) test data.
先自己写一遍答案,再对照解题步骤。
Perform a manual dry run of the following algorithm using a trace table to identify duplicate adjacent numbers in a list.
Algorithm:
1. Set \(L = [5, 2, 8, 8, 3]\)
2. Set \(found = False\)
3. Set \(i = 0\)
4. While \(i < 4\) and \(found\) is \(False\):
a. If \(L[i] == L[i+1]\):
i. \(found = True\)
ii. \(duplicate = L[i]\)
b. \(i = i + 1\)
Provide a trace table showing the values of \(i\), \(L[i]\), \(L[i+1]\), and \(found\) at the start of each loop iteration until the algorithm terminates.
先自己写一遍答案,再对照解题步骤。
* thinka提供的内容由AI生成,可能并非总是准确或最新。请将其用作辅助资源,并与官方材料进行核实。
想多做几道同类题目?立即开始练习这个课题,边做边批改。
立即练习