Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 9

Implement a function that returns multiple values

Easy

10 minute session

Summary

Return multiple values from a function using tuples so callers can unpack results.

Problem statement

Write sum_and_product(a, b) which takes two numeric arguments and returns two values: their sum and their product. The return should be a tuple so callers can unpack it like s, p = sum_and_product(2, 3).

Task

Implement sum_and_product(a, b) that returns both the sum and the product of two numbers as a tuple (sum, product).

Examples

Sum and product of 2 and 3

Input

sum_and_product(2, 3)

Output

(5, 6)

Explanation

2 + 3 = 5, 2 * 3 = 6, so return the tuple (5, 6).

Input format

Two numeric arguments a and b.

Output format

A tuple with two elements: (a + b, a * b).

Constraints

Do not use external libraries. Handle ints and floats. Return a tuple so Python's default repr matches expected outputs.

Samples

Sample input 0

sum_and_product(0, 5)

Sample output 0

(5, 0)

Explanation 0

0 + 5 = 5, 0 * 5 = 0.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

09:03 PM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.