question 98 Fundamentals Integration · medium
The next invoice number
An accounting system numbers invoices with a prefix and a counter, such as INV-0099. The next number keeps the prefix exactly and adds 1 to the counter, keeping the counter's width with leading zeros (INV-0100). When the counter overflows its width, it simply grows (INV-999 → INV-1000). The counter is the run of digits at the very end; a number that doesn't end in a digit is invalid.
Function
next_invoice(number)Returnsthe same prefix with the counter plus 1, zero-padded to at least the old width;
None if number doesn't end in a digitExamples
callnext_invoice('INV-0099')returns'INV-0100'
callnext_invoice('INV-999')returns'INV-1000'
callnext_invoice('A7')returns'A8'
callnext_invoice('DRAFT')returnsNone