Bird
0
0

How can you write a method that returns the sum of squares of two numbers x and y in one line?

hard📝 Application Q9 of 15
Python - Methods and Behavior Definition
How can you write a method that returns the sum of squares of two numbers x and y in one line?
Adef sum_squares(x, y): print(x**2 + y**2)
Bdef sum_squares(x, y): return x**2 + y**2
Cdef sum_squares(x, y): return (x + y)**2
Ddef sum_squares(x, y): return x * x + y
Step-by-Step Solution
Solution:
  1. Step 1: Understand the sum of squares formula

    Sum of squares means x**2 + y**2, not square of sum.
  2. Step 2: Identify correct one-line return

    def sum_squares(x, y): return x**2 + y**2 returns correct sum; A prints instead; C returns square of sum; D returns incorrect sum.
  3. Final Answer:

    def sum_squares(x, y): return x**2 + y**2 -> Option B
  4. Quick Check:

    Return sum of squares with correct expression [OK]
Quick Trick: Use return with correct math expression [OK]
Common Mistakes:
  • Returning square of sum instead of sum of squares
  • Using print instead of return
  • Incorrect arithmetic expressions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes