Advertisement
Spocoman

09. Left and Right Sum

Dec 23rd, 2021 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. num = int(input())
  2. left_sum = 0
  3. right_sum = 0
  4.  
  5. for i in range(num):
  6.     left_sum += int(input())
  7.  
  8. for i in range(num):
  9.     right_sum += int(input())
  10.  
  11. if left_sum == right_sum:
  12.     print(f'Yes, sum = {left_sum}')
  13. else:
  14.     print(f'No, diff = {abs(left_sum - right_sum)}')
  15.  
  16.  
  17. РЕШЕНИЕ С ЕДИН FOR:
  18.  
  19. num = int(input())
  20. left_sum = 0
  21. right_sum = 0
  22.  
  23. for i in range(-num, num):
  24.     if i < 0:
  25.         left_sum += int(input())
  26.     else:
  27.         right_sum += int(input())
  28.  
  29. if left_sum == right_sum:
  30.     print(f'Yes, sum = {left_sum}')
  31. else:
  32.     print(f'No, diff = {abs(left_sum - right_sum)}')
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement