Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_number_suffix(n: int) -> str:
- """Adds suffix to passed in number, ie 1 becomes 1st, 13 becomes 13th....
- :param int number to add suffix
- : returns str
- """
- if 4 <= n <= 20 or 24 <= n % 100 <= 30: # teens
- suffix = "th"
- else:
- suffix = {1: 'st', 2: 'nd', 3: 'rd'}.get(n % 10, 'th')
- return f'{n}{suffix}'
Advertisement
Add Comment
Please, Sign In to add comment