Answer to Question #97822 in Python for john

Question #97822
You decide to go for a very long drive on a very straight road. Along this road are five cities. As you travel, you record the distance between each pair of consecutive cities. You would like to calculate a distance table that indicates the distance between any two of the cities you have encountered. Write a Python program, including comments, that will ask user for a string of integers separated by comma. You program must display a 5 by 5 array of numbers representing the distance between cities.
1
Expert's answer
2019-11-05T07:42:01-0500

a=str(input('Write integers, separatrd by a comma: ')) #ask user to write integers

b=a.split(',') # change the string to list of numbers

c=[0]*len(b) # list contans nulls

d=['first', 'second', 'third', 'fourth', 'fifth', 'first'] #list contains names of sities

for i in range(len(b)):

c[i]=int(b[i]) # change nulls to distances between the sities

print('distance between the ' + d[i] + ' and the ' + d[i+1] + ' sities: ', c[i]) # output


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS