Answer to Question #319478 in Python for Psy

Question #319478

Find the difference numbers 7 5 1


Output: 7-5=2, 5-1=4, 7-1=6.


So output is least difference 2



1
Expert's answer
2022-03-28T08:03:36-0400
diff = []
print("Enter list (separated by a space):")
a = input().split()
for i in range(len(a)):
    a[i] = int(a[i])
for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        diff.append(a[i] - a[j])
        print(f"{a[i]}-{a[j]}={a[i]-a[j]}", end=" ")
min = diff[0]
for i in range(len(diff)):
    if min > diff[i]:
         min = diff[i]
print(f"\nLeast difference: {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