Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Implement a function that returns multiple values

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

Python practice10 minFunctions & ScopeBeginnerLast updated March 17, 2026

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)

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 1

Input

sum_and_product(0, 5)

Output

(5, 0)

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