SimeonTs

SUPyF2 Lists Basics Lab - 05. Numbers Filter

Sep 27th, 2019
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. """
  2. Lists Basics - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1724#4
  4.  
  5. SUPyF2 Lists Basics Lab - 05. Numbers Filter
  6.  
  7. Problem:
  8. You will receive a single number n. On the next n lines you will receive integers.
  9. After that you will be given one of the following commands:
  10. • even
  11. • odd
  12. • negative
  13. • positive
  14. Filter all the numbers that fit in the category (0 counts as a positive). Finally, print the result.
  15.  
  16. Example:
  17. Input:
  18. 5
  19. 33
  20. 19
  21. -2
  22. 18
  23. 998
  24. even
  25. Output:
  26. [19, -2, 18, 998]
  27.  
  28. Input:
  29. 3
  30. 111
  31. -4
  32. 0
  33. negative
  34. Output:
  35. [-4]
  36. """
  37. even = []
  38. odd = []
  39. negative = []
  40. positive = []
  41.  
  42. for how_many_times in range(int(input())):
  43.     digit = int(input())
  44.     if digit % 2 == 0:
  45.         even += [digit]
  46.     else:
  47.         odd += [digit]
  48.     if digit < 0:
  49.         negative += [digit]
  50.     else:
  51.         positive += [digit]
  52. print(eval(input()))
Add Comment
Please, Sign In to add comment