A Python 3 program must divide a 36-dollar bill equally among a positive number of guests, with no extra charges. The variable guests already contains an integer when this statement runs:
print(36 / guests + 2)
Consider separate runs with guests equal to 0 and 4. Select every correct statement.
With four guests, the printed result violates the stated bill-sharing requirement.
With four guests, completing execution proves that the formula is correct.
With zero guests, producing no result makes the defect a syntax error.
With zero guests, evaluating the division causes a runtime error.
Unlock full course notes by signing up
A mean that loses its fraction
A Python 3 program must report the arithmetic mean of five quiz marks whose total is 83 points. Fractional means are allowed. For these positive values, // discards the fractional part of the quotient.
By how many points is the printed mean below the required mean? Answer in points, to one decimal place.
A crash and a quiet wrong answer
A student writes two short Python programs. Neither contains a grammar mistake, so Python accepts both files and starts running them.
Program 1 should display a test score:
Program 2 should convert 20 °C to degrees Fahrenheit:
When one failure hides another
A school shop requires its program to add a 6-dollar delivery charge to the sum of item prices, then apply a 20% surcharge to that combined amount. A student writes this Python 3 function:
Python list positions start at 0. The function len gives the number of items, and range(n) supplies integers from 0 through n - 1.
Find the first invalid list index reached by the original program, as an exact integer. A programmer then repairs only the loop bounds so that every item price is added exactly once, leaving the return statement unchanged. Find both the amount this repaired version returns and the amount required by the specification, in dollars to one decimal place.
Tests that miss a largest-value bug
The Python function below is meant to return the largest number in a non-empty list. It contains no syntax errors and never crashes on lists of numbers.
A tester runs it on the four input lists in the table. For each list, enter the value the function actually returns, the true largest value in the list, and whether the two match (type yes or no).