Skip to content

Instantly share code, notes, and snippets.

@duonghuuphuc
Created October 24, 2024 15:17
Show Gist options
  • Save duonghuuphuc/98933efbd27af46d79f36494915d6988 to your computer and use it in GitHub Desktop.
Save duonghuuphuc/98933efbd27af46d79f36494915d6988 to your computer and use it in GitHub Desktop.

Python Program to Generate a Random Phone Number in Vietnam Format

This Python program generates a random 10-digit phone number in the Vietnam format. The first three digits are predefined from a list of valid prefixes, while the remaining digits are randomly generated.

Code

import random

def generate_phone_number():
    prefixes = ['097', '098', '086', '032', '035', '037', '038', '039', '091', '094', '081', '085', '083', '070', '079', '077', '076', '090', '093', '089']
    prefix = random.choice(prefixes)
    suffix = ''.join(random.choices('0123456789', k=7))
    return prefix + suffix

if __name__ == "__main__":
    phone_number = generate_phone_number()
    print(f"Generated phone number: {phone_number}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment