Question

In: Computer Science

Please use PYTHON on colab notebook Here's the list: [[‘Five Guys’,1,3],[‘Burger King’,5,7],['Nack Stick’,4,4][‘Pizza Hut’,7,2],[‘Taco Time’,1,8],[‘McDonalds’,5,7],['Taco Bell’,4,3]]...

Please use PYTHON on colab notebook

Here's the list:

[[‘Five Guys’,1,3],[‘Burger King’,5,7],['Nack Stick’,4,4][‘Pizza Hut’,7,2],[‘Taco Time’,1,8],[‘McDonalds’,5,7],['Taco Bell’,4,3]]

The task is to write a loop that uses the function function2(a,b) (I have it down below)to create a dictionary called bus_dic which has all the business names above as keys and has it followed by the flying distance.f

For example,

when you type in bus_dist["Five Guys"] you should get 3.16227766

If you need anything else, please leave a message. Thank you!

The functio2

def function2(a,b):
   c = a*a + b*b
   d = c ** 0.5
   return d

Solutions

Expert Solution

Python code:

def function2(a,b):#required function

   c = a*a + b*b

   d = c ** 0.5

   return d

lis=[['Five Guys',1,3],['Burger King',5,7],['Nack Stick',4,4],['Pizza Hut',7,2],['Taco Time',1,8],['McDonalds',5,7],['Taco Bell',4,3]]#list of values

bus_dist={}#initializing dictionary bus_dist

for i in lis:#adding elements to the dictionary using a loop

    bus_dist[i[0]]=function2(i[1],i[2])#adding elements

bus_dist["Five Guys"]#printing

Screenshot of code and output:


Related Solutions

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT