Repository navigation
exercise6/answer.py: is the last if/else inverted? #23
|
In items = input("Enter items: ")
if items:
print(f"Empty, {items}")
else:
print("Items present")If the user types something, Was this a deliberate test of truthiness, or a copy-paste flip? And what would the corrected version look like? |
Replies: 1 comment
|
Good catch — it is inverted, and there's a second bug in the same two lines. The block at the end of items = input("Enter items: ")
if items:
print(f"Empty, {items}")
else:
print("Items present")
Corrected version, matching Module 06's TODO 4 wording ("Empty list" / "Items present"): items = input("Enter items: ")
if items:
print(f"Items present: {items}")
else:
print("Empty list")Worth noting the file already does truthiness correctly ten lines up — the One curriculum-level detail: |
Good catch — it is inverted, and there's a second bug in the same two lines.
The block at the end of
answers/exercise6/answer.py:input()returns astr; a non-empty string is truthy, so typing anything lands inprint(f"Empty, {items}"). Typing nothing produces""(falsy) and prints "Items present". Both cases say the opposite of what's true.f"Empty, {items}"would print the user's items after the word "Empty". The message that should include the items is the "present" one.Corre…