Question: Python 3 Question Below is question given and the code i have that is not working in random test cases. def trip(max_distance, places): if max_distance
Python 3 Question
Below is question given and the code i have that is not working in random test cases.


def trip(max_distance, places): if max_distance return None else: l =list(locations.values()) l.append((max_distance)) l.sort() i=l.index(max_distance) i=i-1 if i return 'no where' else: for k,v in locations.items(): if v == l[i]: return k
if __name__ == '__main__': locations = {'Beijing': 6836, 'Los Angeles': 2448, 'New York': 50, 'San Francisco': 2569, 'Washington D.C.': 204, 'Pittsburgh': 315, 'Columbus': 477, 'Tokyo': 6749, 'Moscow': 4672, 'Paris': 3649, 'Las Vegas': 2230, 'Kansas City': 1095, 'Iowa City': 913, 'Orlando': 940, 'Island of Hawaii': 4927, 'City B': 1399} print("Testing Part I") print("Testing trip() for max_distance = 1000, places = locations: " + str(trip(1000, locations))) print("Testing trip() for max_distance = 0, places = locations: " + str(trip(0, locations))) print("Testing trip() for max_distance = 3848, places = locations: " + str(trip(3848, locations))) print("Testing trip() for max_distance = 10, places = locations: " + str(trip(10, locations))) print() Part I: Farthest Destination (20 points) Write a function trip that takes the following arguments, in this order: 1. max.distance: an integer that represents how far a person can travel based on the plane ticket he/she is holding for a one-way trip. 2. places: a dictionary that maps destinations (as strings) to distances (as integers). For example, if the key LA' is mapped to the value 3000, this means that the destination LA is 3000 miles away from where the person is right now. Your function should scan through the dictionary, then find one farthest destination that the person can travel to based on the max.distance for a one-way trip. CSE 101 - Fall 2017 Lab #7 Page 1 Note: If max.distance is a number that's zero or less, this means the plane ticket is invalid, and your function should return the value None (NOT the string 'None). If the plane ticket can't take the person anywhere, returrn nowhere'. Also, you don't need to worry about two destinations having the same distance
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
