Beispiel #1
0
def location_by_zip(zip_codes, code):
    zip_codes = hw4_util.read_zip_all()
    i = 0
    while i < len(zip_codes):
        if zip_codes[i][0] == code:
            return zip_codes[i][1], zip_codes[i][2], zip_codes[i][
                3], zip_codes[i][4], zip_codes[i][5]
        i += 1
Beispiel #2
0
def zip_codes(zip_codes, location):
    zip_codes = hw4_util.read_zip_all()
    (city, state) = location
    zip_list = []
    i = 0
    while i < len(zip_codes):
        if zip_codes[i][3] == city and zip_codes[i][4] == state:
            zip_list.append(zip_codes[i][0])
        i += 1
    return zip_list
Beispiel #3
0
def location_by_zip(zip_codes, code):
    '''
    The purpose of this fuction is to find location information corresponding to the
    specified ZIP code, code. The other argument for this function is zip_codes, a list of ZIP codes data in the format, returned by read_zip_all().
    '''
    zip_codes = hw4_util.read_zip_all()
    i = 0
    while i < len(zip_codes):
        if zip_codes[i][0] == code:
            return zip_codes[i][1], zip_codes[i][2], zip_codes[i][
                3], zip_codes[i][4], zip_codes[i][5]
        i += 1
Beispiel #4
0
def zip_by_location(zip_codes, location):
    '''
    The purpose of this function is to return a list of zip codes, zip_list, for a inputted location, location, which is a tuple created from a given city and state. The other argument for this function is zip_codes, a list of ZIP codes data in the format, returned by read_zip_all().
    '''
    zip_codes = hw4_util.read_zip_all()
    (city, state) = location
    zip_list = []
    i = 0
    while i < len(zip_codes):
        if zip_codes[i][3] == city and zip_codes[i][4] == state:
            zip_list.append(zip_codes[i][0])
        i += 1
    return zip_list
Beispiel #5
0
def location_by_zip

def zip_by_location(zip_codes, location):
	city, state = location
	codes = []
	for data in (zip_codes):
		if data[3] == city and data[4] == state:
			codes.append(data[0])

	return codes


zip_codes = hw4_util.read_zip_all()

command = ''

while command != 'end':
	
	command = input("Command ('loc', 'zip', 'dist', 'end') => ")
	print(command)

	if command == 'loc':
		zipcode = input('Enter a ZIP code to lookup => ')
		print(zipcode)

	elif command == 'zip':
		city = input('Enter a city name to lookup => ')
		print(city)
		state = input('Enter a state name to lookup => ')
		print(state)
		city = city.title()
		state = state.upper()
		zips = zip_by_location(zip_codes, (city, state))
		if len(zips) == 0:
			print('No ZIP code found for {}, {}'.format(city, state))
		else:
			print('The following ZIP code(s) found for {}, {}: '.format(city, state), end='')
			for i in range(len(zips) - 1):
				print(zips[i], end=', ')
			print(zips[len(zips) - 1])
		print()

	elif command == 'dist':
		pass

	elif command == 'end':
		pass

	else:
		print('Invalid command, ignorin')
Beispiel #6
0
##arbitrary string (in this case, the word selected is "begin") used in order to begin the while loop
command = "begin"

##while loop used to continue to ask the user for command inputs until they enter the command "end"
while not command.lower() == 'end':
    command = input("Command ('loc', 'zip', 'dist', 'end') => ")
    print(command)

    ##if statement for if the user enters "loc" (case insentive, hence the lower())
    if command.lower() == 'loc':
        zip_code = str(input("Enter a ZIP code to lookup => "))
        print(zip_code)
        i = 0
        all_zips = []
        zip_codes = hw4_util.read_zip_all()
        ##while loop used to append all of the zip codes from the lists in zip_codes into the list all_zips, creating a list of all of the zip codes
        while i < len(zip_codes):
            all_zips.append(zip_codes[i][0])
            i += 1
        ##the created list all_zips is being used to check if the inputted code is valid, or is present in the all_zips list
        if all_zips.count(zip_code) == 0:
            print("Invalid or unknown ZIP code")
        elif all_zips.count(zip_code) > 0:
            results = location_by_zip(zip_codes, zip_code)
            print("ZIP code {} is in {}, {}, {} county,".format(
                zip_code, results[2], results[3], results[4]))
            print("\tcoordinates: ({},{})".format(convert_lat(results[0]),
                                                  convert_long(results[1])))
        print()