Phone Prefix

Report a typo

You're working with a code used for phone numbers in a telecom company. Take a look at the code below to understand how the phone numbers are being processed.

def format_phone_numbers(phone_numbers: dict[str, str], country_code: str | None) -> dict[str, str]:

    if not country_code:
        country_code = "+1"

    formatted = {}
    for name, number in phone_numbers.items():
        if not number.startswith("+"):
            formatted[name] = country_code + number
        else:
            formatted[name] = number

    return formatted

Describe the functionality of this code for an AI assistant by focusing on its overall purpose and what it achieves, rather than detailing each line. Emphasize the main function and the rules it follows to accomplish its task.

The AI assistant will generate a new code based on your description. The generated code doesn't need to be identical to the code above, but it should achieve the same outcome.
Write a prompt to generate Python 3 code
GENERATED CODE:





Create a free account to access the full topic