Advertisement
svephoto

Odd / Even Position [Python]

Jul 3rd, 2021
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import sys
  2.  
  3. n = int(input())
  4. OddSum = 0
  5. EvenSum = 0
  6. OddMin = sys.maxsize
  7. OddMax = -sys.maxsize
  8. EvenMin = sys.maxsize
  9. EvenMax = -sys.maxsize
  10. for i in range(1, n + 1):
  11.     num = float(input())
  12.     if i % 2 == 0:
  13.         EvenSum += num
  14.         if num > EvenMax:
  15.             EvenMax = num
  16.         if num < EvenMin:
  17.             EvenMin = num
  18.     else:
  19.         OddSum += num
  20.         if num > OddMax:
  21.             OddMax = num
  22.         if num < OddMin:
  23.             OddMin = num
  24. print(f"OddSum={OddSum:.2f},")
  25. if OddMin != sys.maxsize:
  26.     print(f"OddMin={OddMin:.2f},")
  27. else:
  28.     print("OddMin=No,")
  29. if OddMax != -sys.maxsize:
  30.     print(f"OddMax={OddMax:.2f},")
  31. else:
  32.     print("OddMax=No,")
  33. print(f"EvenSum={EvenSum:.2f},")
  34. if EvenMin != sys.maxsize:
  35.     print(f"EvenMin={EvenMin:.2f},")
  36. else:
  37.     print("EvenMin=No,")
  38. if EvenMax != -sys.maxsize:
  39.     print(f"EvenMax={EvenMax:.2f}")
  40. else:
  41.     print("EvenMax=No")
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement