A Python importer receives a caller-owned list of dictionaries. Every dictionary initially contains a name string and a quantity integer. Validation requires a nonempty name and a quantity from 0 through 500. Strings and integers are immutable, but lists and dictionaries are mutable. After the import returns, the caller may change its list or any original dictionary. There are no concurrent changes during import.
Which strategies preserve the imported names and quantities as the validated snapshot despite those later caller changes? Select every correct strategy.
Create new dictionaries containing only the name and quantity values, validate those new dictionaries, and retain them in a new private list.
Create a tuple of name and quantity pairs containing only strings and integers, validate the derived pairs, and retain that new tuple of tuples.
Copy the outer list, validate its dictionaries, and retain that copied list while continuing to use the original dictionary objects.
Validate every original dictionary, place those same dictionaries inside a tuple, and retain the tuple instead of retaining the caller's list.
Unlock full course notes by signing up
Check endpoints and input representations
A telemetry receiver accepts a retry count only if its input type is integer and its value is from 0 through 4, inclusive. It performs no conversion from another type. Complete every decision cell with exactly accept or reject, using the supplied input types.
Trace damage from a late validation check
A booking prototype runs the following Python code for one request. Each place costs 6 credits. Its specification says that a rejected request must leave the credit balance and available places unchanged.
Find the actual credit balance after execution and the number of credits wrongly removed by this rejected request. Give both answers in whole credits, to zero decimal places.
Sequence the checks in a defensive withdrawal method
A method withdraw(request) removes money from a stored account balance. The request object may be missing, and its amount field arrives from a web form, so it may not be a whole number. Valid withdrawals are 1 to 50000 cents inclusive and must not exceed the balance. The balance is held by a ledger service, and that service must only ever receive amounts already known to lie in the permitted range. Arrange the steps in the order a defensive implementation should perform them.
Guard an addition against integer overflow
A Java wallet service stores a balance in cents as an int. The largest int value is 2147483647, and when a sum exceeds it, the result wraps around by subtracting 232=42949672962^{32} = 4294967296232=4294967296. The current balance is 2147000000 cents.
A safe deposit guard is written as if (amount > Integer.MAX_VALUE - balance) reject();. A naive guard is written as if (balance + amount > Integer.MAX_VALUE) reject();. A deposit of 500000 cents arrives.
Find the largest deposit, in whole cents, that the safe guard accepts. Find the value, in cents, that the expression balance + amount actually produces for the 500000-cent deposit. Then state whether the naive guard leaves that deposit accepted or rejected (answer with one word).