A Python 3 ticket system calls the following function independently for each input string. Complete the outcome table with the exact integer returned, the word invalid, or the word propagates if an exception leaves the function without being caught.
For this question, converting "bad" with int raises ValueError, and integer division by zero raises ZeroDivisionError. Quotation marks in the input column identify strings; do not include quotation marks in your answers.
def ticket_count(text): try: count = int(text) except (ValueError, ZeroDivisionError): return "invalid" else: if count == 0: return 24 // count return count + 2
Unlock full course notes by signing up
Nested try statements with finally
The Python program below processes a list of tokens with a try statement nested inside another. Trace it to the end and give the three integers it prints: the final values of total, handled and cleanups.
Inventory updates across a failed shipment and retry
A simplified Python 3 warehouse script processes shipment attempts. Each tuple contains an item quantity and a parcel count, both stored as strings. The last tuple retries the failed second shipment with a corrected parcel count. Converting "bad" with int raises ValueError.
In a revised version, move stock -= quantity immediately after parcels = int(parcel_text), keeping both statements inside try. Make no other changes. Run each version separately, starting with 25 items in stock and zero items shipped.
Find the final stock for the original version, the final stock for the revised version, and the final shipped total for each version. Give all four quantities in items as exact integers.