-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07_conditionals.py
More file actions
27 lines (20 loc) · 863 Bytes
/
07_conditionals.py
File metadata and controls
27 lines (20 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Exercise 07 — Conditionals.
Tutorial: https://pythonbeginner.help/learn/python-if-else-and-elif-explained/
TODO: classify a number:
1. Set `label` to "positive", "zero", or "negative" based on `n`.
2. Set `parity` to "even" or "odd" using a ternary expression.
Run: python exercises/07_conditionals.py
"""
n = -7
# --- your code below -------------------------------------------------------
if n > 0:
label = ... # TODO: "positive"
elif n < 0:
label = ... # TODO: "negative"
else:
label = ... # TODO: "zero"
parity = ... # TODO: "even" if n % 2 == 0 else "odd"
# --- self-check (don't edit) ----------------------------------------------
assert label == "negative", "for n = -7, label should be 'negative'"
assert parity == "odd", "for n = -7, parity should be 'odd'"
print("✅ Passed!", "label:", label, "| parity:", parity)