Skip to content
Discussion options

You must be logged in to vote

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:

items = input("Enter items: ")
if items:
    print(f"Empty, {items}")
else:
    print("Items present")
  1. Branch logic is flipped. input() returns a str; a non-empty string is truthy, so typing anything lands in print(f"Empty, {items}"). Typing nothing produces "" (falsy) and prints "Items present". Both cases say the opposite of what's true.
  2. The f-string leaks the input into the wrong message. Even with the branches fixed, 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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dab00gieman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants