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.


Python
credits = 83
places = 7
requested = 9
price = 6

credits -= requested * price
if requested > places:
    status = "rejected"
else:
    places -= requested
    status = "accepted"


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.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Defensive Design Questions: