When I comment on all the key - values in my_dict, I should be given the last line, return 'No distance info to available', but it gives me an error
my_dict = {
# "distance": 500.5,
# 'speed': 60,
# 'time': 55
}
def rout_info(my_data):
if type(my_data["distance"]) is int:
return f'Distance to your distination is {my_data["distance"]}'
elif 'speed' and 'time' in my_data:
return f'Disntace to your destination is {my_data["speed"] * my_data["time"]}'
else:
return 'No distance info to available'
print(rout_info(my_dict))
My Error:
Traceback (most recent call last):
print(rout_info(my_dict))
^^^^^^^^^^^^^^^^^^
if type(my_data["distance"]) is int:
~~~~~~~^^^^^^^^^^^^
KeyError: 'distance'
When I remove the comment, the if operator and the elif operator work for me