A file-opening program uses the following Python code. Select every statement that correctly describes its output for the specified input conditions.
if file_exists: if password_ok: print("Opened") else: print("Password needed") print("Finished")
Both inputs store either True or False, and execution always reaches the end of this code.
When file_exists is true, the program prints Opened and then Finished, regardless of the password value.
When file_exists is false, the program prints only Finished, regardless of the password value.
When both input values are true, the program prints Opened and then prints Finished.
When password_ok is false, the program prints Password needed and then Finished, regardless of the file value.
Unlock full course notes by signing up
Carry values through a nested path
A reading challenge calculates reward points with the following Python code. For books = 5 and returned_on_time = False, what is the final value of points? Answer in points, to the nearest whole point.
Count the tests that actually run
A dispatch program runs the following Python code once for each parcel. The variable mass gives the parcel mass in kilograms; express and fragile contain Boolean values.
Count a condition evaluation whenever execution reaches an if and tests its condition. An else does not perform another test.
Across these four independent runs, find the total number of condition evaluations and the number of those evaluations that return true. Enter both counts as exact integers.
The cost of moving an else
A festival checkout has two versions of its ticket-pricing code. Each version starts independently, and both inputs are either True or False.
Program A
Program B