Answer to Question #314562 in Python for Manish

Question #314562

Minimal Absolute Difference

There are N pyramids in a line.You are given their heights as a list of integers.Write a program to find the minimum absolute difference between the heights of any two different pyramids.


Input

The input is a single line containing space-separated integers.


Output

The output should be a single line containing the minimum absolute difference of any two different pyramid heights.


Explanation

Given Pyramid heights are 7 1 5.

The absolute difference between the heights of any two different pyramids are


1
Expert's answer
2022-03-20T14:41:56-0400
line = input()
pyramids = [int(w) for w in line.split()]

min = None
n = len(pyramids)
for i in range(n-1):
    for j in range(i+1, n):
        difference = abs(pyramids[i] - pyramids[j])
        if min is None:
            min = difference
        elif min > difference:
            min = difference
print('The absolute difference between the heights of any two different pyramids are', min)

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