Over the domain given by a list of integers, answer three questions:
- ∀x (x is even): is every number even?
- ∃x (x < 0): is some number negative?
- ∀x ∃y (y = −x): does every number's negative also appear in the list? (0 is its own negative.)
Input
One line of 1 to 100 integers, separated by spaces.
Output
Three lines: all even: yes (or no), some negative: yes (or no) and negatives present: yes (or no).
Examples
Example 1 · Input
2 4 -2 -4
Expected output
all even: yes some negative: yes negatives present: yes
Example 2 · Input
1 2 3
Expected output
all even: no some negative: no negatives present: no
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
all(x % 2 == 0 for x in nums) tests 'for all'.
Hint 2
any(x < 0 for x in nums) tests 'there exists'.
Hint 3
The third is ∀x ∃y (y = −x): all(-x in nums for x in nums). Zero is its own negative.
Solution
Show one correct solution (try it yourself first)
nums = [int(x) for x in input().split()]
yes = lambda b: "yes" if b else "no"
print("all even:", yes(all(x % 2 == 0 for x in nums)))
print("some negative:", yes(any(x < 0 for x in nums)))
print("negatives present:", yes(all(-x in nums for x in nums)))