Random Address Generator by Country Code

  • Share this:

Code introduction


The function generates a random address for the specified country code, including street, city, state, postal code, and country.


Technology Stack : Mimesis library

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
from mimesis import Address, Company, Datetime, Internet, Person

def generate_random_address(country_code='US'):
    """
    Generate a random address for the given country code.
    """
    address_generator = Address(country_code=country_code)
    address = address_generator.street()
    city = address_generator.city()
    state = address_generator.state()
    postal_code = address_generator.postal_code()
    country = address_generator.country()
    return f"{address}, {city}, {state}, {postal_code}, {country}"