Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- n = int(input())
- odd_min = sys.maxsize
- odd_max = -sys.maxsize
- odd_sum = 0
- even_min = sys.maxsize
- even_max = -sys.maxsize
- even_sum = 0
- for i in range(1, n + 1):
- current_num = float(input())
- if i % 2 == 1:
- odd_sum += current_num
- if current_num < odd_min:
- odd_min = current_num
- if current_num > odd_max:
- odd_max = current_num
- else:
- even_sum += current_num
- if current_num < even_min:
- even_min = current_num
- if current_num > even_max:
- even_max = current_num
- if n == 0:
- print('OddSum=0.00,\nOddMin=No,\nOddMax=No,')
- else:
- print(f'OddSum={odd_sum:.2f},\nOddMin={odd_min:.2f},\nOddMax={odd_max:.2f},')
- if n <= 1:
- print(f'EvenSum=0.00,\nEvenMin=No,\nEvenMax=No')
- else:
- print(f'EvenSum={even_sum:.2f},\nEvenMin={even_min:.2f},\nEvenMax={even_max:.2f}')
- РЕШЕНИЕ С ЛИСТ:
- n = int(input())
- odd = []
- even = []
- for i in range(n):
- odd.append(float(input())) if i % 2 == 0 else even.append(float(input()))
- if len(odd) == 0:
- print('OddSum=0.00,\nOddMin=No,\nOddMax=No,')
- else:
- print(f'OddSum={sum(odd):.2f},\nOddMin={min(odd):.2f},\nOddMax={max(odd):.2f},')
- if len(even) == 0:
- print(f'EvenSum=0.00,\nEvenMin=No,\nEvenMax=No')
- else:
- print(f'EvenSum={sum(even):.2f},\nEvenMin={min(even):.2f},\nEvenMax={max(even):.2f}')
- РЕШЕНИЕ С ЛИСТ И ТЕРНАРЕН ОПЕРАТОР:
- n = int(input())
- odd = []
- even = []
- for i in range(n):
- odd.append(float(input())) if i % 2 == 0 else even.append(float(input()))
- print(f'OddSum={(sum(odd) if len(odd) > 0 else 0):.2f},\nOddMin={"No" if n == 0 else f"{min(odd):.2f}"},\nOddMax={"No" if n == 0 else f"{max(odd):.2f}"},')
- print(f'EvenSum={(sum(even) if len(even) > 0 else 0):.2f},\nEvenMin={"No" if n <= 1 else f"{min(even):.2f}"},\nEvenMax={"No" if n <= 1 else f"{max(even):.2f}"}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement