DEV Community

loading...

Discussion on: Daily Challenge #282 - Car License Plate Calculator

Collapse
rrampage profile image
Raunak Ramakrishnan • Edited

letters = 'abcdefghijklmnopqrstuvwxyz'
def find_the_number_plate(n):
    # As serial numbers go from 001 to 999, we take n % 999 and convert it to a 0 padded string
    ser = str(n%999 + 1).rjust(3, '0')
    # To find the letters, we need to divide by 999 and then repeatedly divide by 26 to get the 3 letters
    l = n//999
    return letters[l%26]+letters[(l//26)%26]+letters[(l//(26*26))%26] + ser