Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def filter_numbers(numbers, command):
- if command == "even":
- return [num for num in numbers if num % 2 == 0]
- elif command == "odd":
- return [num for num in numbers if num % 2 != 0]
- elif command == "negative":
- return [num for num in numbers if num < 0]
- elif command == "positive":
- return [num for num in numbers if num >= 0]
- n = int(input())
- numbers = [int(input()) for _ in range(n)]
- command = input()
- filtered_numbers = filter_numbers(numbers, command)
- print(filtered_numbers)
Advertisement
Add Comment
Please, Sign In to add comment