def generate_url(query, num, start, recent, country_code):
    """(str, str, str) -> str
    A url in the required format is generated.
    """
    query = '+'.join(query.split())
    url = ('https://www.google.com/search?q=' + query + '&num=' + num +
        '&start=' + start)
    if recent in ['h', 'd', 'w', 'm', 'y']:
        url += '&tbs=qdr:' + recent
    if country_code is not None:
        url += '&gl=' + country_code
    return url
