D. Callback is called immediately instead of passed as a function
Solution
Step 1: Check how callback is passed
The code uses callback() which calls the function immediately instead of passing the function reference.
Step 2: Understand correct callback usage
We must pass callback without parentheses so it is called on message arrival.
Final Answer:
Callback is called immediately instead of passed as a function -> Option D
Quick Check:
Pass callback function, not call it [OK]
Hint: Pass callback without () to create_subscription [OK]
Common Mistakes:
Adding parentheses to callback in subscription
Omitting queue size argument (optional in some versions)
Using variable instead of string for topic name
5.
You want to create a subscriber node that listens to the topic 'sensor_data' and prints only messages where the data is greater than 10. Which callback function correctly implements this?
def callback(msg):
# Fill in the condition
if ____:
print(f"Data: {msg.data}")
hard
A. msg.data > 10
B. msg.data >= 10
C. msg.data < 10
D. msg.data == 10
Solution
Step 1: Understand the requirement
We want to print messages only if data is greater than 10, so the condition must check msg.data > 10.
Step 2: Compare options with condition
msg.data > 10 matches exactly 'greater than 10'. Others check equal or less, which do not meet the requirement.
Final Answer:
msg.data > 10 -> Option A
Quick Check:
Condition for data > 10 is msg.data > 10 [OK]
Hint: Use > 10 to filter messages with data above 10 [OK]
Common Mistakes:
Using >= instead of > changes condition
Using < or == prints wrong messages
Not adding any condition prints all messages
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.