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により生成されているため、内容が正確でない場合があります。補助教材としてご使用いただき、公式の教材と合わせてご確認ください。
模範解答は見ました。次はあなたの答案を採点します。
このページは良い答案の形を示せますが、あなたの答案に何が足りないかは教えられません。thinka は実際の採点基準に沿って記述答案を約 15 秒で採点します。
同じような問題をもっと解きたい?このトピックの新しい問題を、解きながら採点。
練習を始める