Bird
0
0

Which of these methods correctly returns the square of a number n?

easy📝 Conceptual Q2 of 15
Python - Methods and Behavior Definition
Which of these methods correctly returns the square of a number n?
Adef square(n): return n + n
Bdef square(n): print(n * n)
Cdef square(n): n * n
Ddef square(n): return n * n
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct use of return for squaring

    Only def square(n): return n * n uses return and multiplies n by itself.
  2. Step 2: Check other options for errors

    def square(n): print(n * n) prints but does not return; C lacks return; D returns sum, not square.
  3. Final Answer:

    def square(n): return n * n -> Option D
  4. Quick Check:

    Return with correct expression = correct method [OK]
Quick Trick: Return must send the calculated value back [OK]
Common Mistakes:
  • Using print instead of return
  • Forgetting return keyword
  • Returning wrong calculation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes