Bird
0
0

Find the error in this method and choose the correct fix:

medium📝 Debug Q14 of 15
Python - Methods and Behavior Definition
Find the error in this method and choose the correct fix:
def greet(name):
    print("Hello, " + name)

message = greet("Alice")
print(message)
ARemove the argument <code>name</code> from the method.
BAdd <code>print</code> before calling <code>greet</code>.
CChange <code>message</code> to <code>greet</code> in the last print.
DChange <code>print</code> to <code>return</code> inside the method.
Step-by-Step Solution
Solution:
  1. Step 1: Identify the problem with return value

    The method prints but does not return a value, so message is None.
  2. Step 2: Fix by returning the greeting string

    Replace print with return to send the greeting back.
  3. Final Answer:

    Change print to return inside the method. -> Option D
  4. Quick Check:

    Return greeting to assign message [OK]
Quick Trick: Use return to get value, not print [OK]
Common Mistakes:
  • Expecting print to return a value
  • Removing needed parameters
  • Changing variable names incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes