# provided input x = 100 y = 100 # answer to this input: LEADBETTERS II from csv import reader import math def distance(x_1, y_1, x_2, y_2): return math.sqrt((x_1 - x_2)**2 + (y_1 - y_2)**2) def closest_restaurant(x,y): opened_file = open('restaurants.csv') read_file = reader(opened_file) restaurants_csv = list(read_file) restaurants_csv = restaurants_csv[1:] minimum = None closest_name = None for row in restaurants_csv: rest_name = row x_cor = int(row) y_cor = int(row) if minimum is None or distance(x_cor, y_cor, x, y) < minimum: minimum = distance(x_cor, y_cor, x, y) closest_name = rest_name return closest_name closest_restaurant(100,100)
Why do we have to declare
closest_name=rest_name in the if line? Can’t we just delete that part of the code and in the final line of the function, replace it with
return rest_name? I need more clarity on the if statement overall as well.