Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- odd_sum = 0
- even_sum = 0
- num = int(input())
- for i in range(1, num + 1):
- if i % 2 == 1:
- odd_sum += int(input())
- else:
- even_sum += int(input())
- if odd_sum == even_sum:
- print('Yes')
- print(f'Sum = {odd_sum}')
- else:
- print('No')
- print(f'Diff = {abs(even_sum - odd_sum)}')
- Решение с тернарен оператор:
- odd_sum = 0
- even_sum = 0
- num = int(input())
- for i in range(1, num + 1):
- odd_sum += int(input()) if i % 2 == 1 else 0
- even_sum += int(input()) if i % 2 == 0 else 0
- print(f'Yes\nSum = {odd_sum}' if odd_sum == even_sum else f'No\nDiff = {abs(even_sum - odd_sum)}')
Add Comment
Please, Sign In to add comment