Answer the question
In order to leave comments, you need to log in
How to compare the values of two lists while iterating over the elements?
How to compare values from two lists while iterating over elements and output the difference?
cost_one = [0.405, 0.405, 0.405, 0.072, 0.03, 0.03, 2.646, 2.691]
cost_two = [0.99, 0.99, 0.99, 0.44, 0.08, 0.03, 2.3, 2.2]
for i in cost_one:
for k in cost_two:
if i > k:
print (i ,'больше', k ,'на' i - k)
else:
print (k ,'больше', i ,'на', k-i)
Answer the question
In order to leave comments, you need to log in
cost_one = [0.405, 0.405, 0.405, 0.072, 0.03, 0.03, 2.646, 2.691]
cost_two = [0.99, 0.99, 0.99, 0.44, 0.08, 0.03, 2.3, 2.2]
for x,y in zip(cost_one, cost_two):
if x < y:
x,y = y,x
print(f'{x} больше {y} на {x-y:.3f}')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question