import random


def generate_nationalities_and_passports(num_users, num_existing_users, 
                                         countries):
    """Generates a list of nationalities and/or passports to be inserted into
    the database.
    
    Keyword arguments:
    num_users -- number of users being created by the script
    num_existing_users -- number of existing users in the evolutions
    countries -- dictionary with values consisting of a tuple of the country
                 name and ISO numeric code
    
    Returns:
    values -- a list of strings to be added to the SQL script
    """
    
    values = []
    template = "({0}, {1}),\n"
    
    country_tuples = list(countries.values())
    
    for i in range(num_users):
        user_id = i + num_existing_users + 1 # +1 because SQL ids start from 1
        
         # Choose a random country and select it's id
        country_id = random.choice(country_tuples)[0]
        
        values.append(template.format(user_id, country_id))
    
    # Make the last comma a semi-colon instead, with a newline for formatting
    values[-1] = values[-1][:-2] + ";\n"
    return values