Advertisement
Spocoman

11. Odd / Even Position

Dec 26th, 2021 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. import sys
  2.  
  3. n = int(input())
  4. odd_min = sys.maxsize
  5. odd_max = -sys.maxsize
  6. odd_sum = 0
  7. even_min = sys.maxsize
  8. even_max = -sys.maxsize
  9. even_sum = 0
  10.  
  11. for i in range(1, n + 1):
  12.     current_num = float(input())
  13.     if i % 2 == 1:
  14.         odd_sum += current_num
  15.         if current_num < odd_min:
  16.             odd_min = current_num
  17.         if current_num > odd_max:
  18.             odd_max = current_num
  19.     else:
  20.         even_sum += current_num
  21.         if current_num < even_min:
  22.             even_min = current_num
  23.         if current_num > even_max:
  24.             even_max = current_num
  25.  
  26. if n == 0:
  27.     print('OddSum=0.00,\nOddMin=No,\nOddMax=No,')
  28. else:
  29.     print(f'OddSum={odd_sum:.2f},\nOddMin={odd_min:.2f},\nOddMax={odd_max:.2f},')
  30.  
  31. if n <= 1:
  32.     print(f'EvenSum=0.00,\nEvenMin=No,\nEvenMax=No')
  33. else:
  34.     print(f'EvenSum={even_sum:.2f},\nEvenMin={even_min:.2f},\nEvenMax={even_max:.2f}')
  35.  
  36.  
  37. РЕШЕНИЕ С ЛИСТ:
  38.  
  39. n = int(input())
  40. odd = []
  41. even = []
  42.  
  43. for i in range(n):
  44.     odd.append(float(input())) if i % 2 == 0 else even.append(float(input()))
  45.  
  46. if len(odd) == 0:
  47.     print('OddSum=0.00,\nOddMin=No,\nOddMax=No,')
  48. else:
  49.     print(f'OddSum={sum(odd):.2f},\nOddMin={min(odd):.2f},\nOddMax={max(odd):.2f},')
  50.  
  51. if len(even) == 0:
  52.     print(f'EvenSum=0.00,\nEvenMin=No,\nEvenMax=No')
  53. else:
  54.     print(f'EvenSum={sum(even):.2f},\nEvenMin={min(even):.2f},\nEvenMax={max(even):.2f}')
  55.  
  56. РЕШЕНИЕ С ЛИСТ И ТЕРНАРЕН ОПЕРАТОР:
  57.  
  58. n = int(input())
  59. odd = []
  60. even = []
  61.  
  62. for i in range(n):
  63.     odd.append(float(input())) if i % 2 == 0 else even.append(float(input()))
  64.  
  65. 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}"},')
  66. 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}"}')
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement