Advertisement
Spocoman

03. List Statistics

Jan 21st, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. num = int(input())
  2. positive = []
  3. negative = []
  4.  
  5. for i in range(num):
  6.     n = int(input())
  7.     if n >= 0:
  8.         positive.append(n)
  9.     else:
  10.         negative.append(n)
  11.  
  12. print(positive)
  13. print(negative)
  14. print(f'Count of positives: {len(positive)}')
  15. print(f'Sum of negatives: {sum(negative)}')
  16.  
  17.  
  18. Или :
  19.  
  20. num = int(input())
  21. positive = []
  22. negative = []
  23. for i in range(num):
  24.     n = int(input())
  25.     positive.append(n) if n >= 0 else negative.append(n)
  26.    
  27. print(f'{positive}\n{negative}\nCount of positives:'
  28.       f' {len(positive)}\nSum of negatives: {sum(negative)}')
  29.  
  30.  
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement