Sujet : Re: Formatting a str as a number
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 25. Aug 2024, 17:42:24
Autres entêtes
Organisation : Stefan Ram
Message-ID : <asked-20240825164104@ram.dialup.fu-berlin.de>
References : 1
Gilmeh Serda <
gilmeh.serda@nothing.here.invalid> wrote or quoted:
Subject explains it, or ask.
Or, you could have asked this way:
|Please fill in the implementation (replacing "pass" below) for
|the following function definition!
|
|def format_number(number_str: str) -> str:
| """
| Format a string of digits as a right-aligned, comma-separated number.
|
| This function takes a string of digits and returns a formatted string where:
| - The number is right-aligned in a field width of 20 characters
| - Commas are inserted as thousand separators
| - Leading spaces are added for alignment
|
| Args:
| number_str (str): A string containing only digits (0-9)
|
| Returns:
| str: A formatted string with the number right-aligned and comma-separated
|
| Examples:
| >>> format_number("123456789")
| ' 123,456,789'
| >>> format_number("1000000")
| ' 1,000,000'
| >>> format_number("42")
| ' 42'
| >>> format_number("1234567890123456789")
| '1,234,567,890,123,456,789'
| """
| pass