SimeonTs

SUPyF2 Lists Basics Lab - 03. Lists Statistics

Sep 27th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. """
  2. Lists Basics - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1724#2
  4.  
  5. SUPyF2 Lists Basics Lab - 03. Lists Statistics
  6.  
  7. Problem:
  8. You will be given a number n. On the next n lines you will receive integers. You have to create and print two lists:
  9. • One with all the positives (including 0)
  10. • One with all the negatives
  11. Finally print the following message: "Count of positives: {count_positives}. Sum of negatives: {sum_of_negatives}"
  12.  
  13. Example:
  14. Input:
  15. 5
  16. 10
  17. 3
  18. 2
  19. -15
  20. -4
  21.  
  22. Output:
  23. [10, 3, 2]
  24. [-15, -4]
  25. Count of positives: 3. Sum of negatives: -19
  26. """
  27. positive_list = []
  28. negative_list = []
  29.  
  30. for how_many_times in range(int(input())):
  31.     digit = int(input())
  32.     if digit >= 0:
  33.         positive_list += [digit]
  34.     else:
  35.         negative_list += [digit]
  36.  
  37. print(positive_list)
  38. print(negative_list)
  39. print(f"Count of positives: {len(positive_list)}. Sum of negatives: {sum(negative_list)}")
Add Comment
Please, Sign In to add comment