Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Swap Values If First Greater

Return the pair (a, b), swapping them if the first is greater than the second.

Python practice10 minControl Flow (If–Else Logic)BeginnerLast updated March 15, 2026

Problem statement

Write a function swap_if_greater(a, b) that returns a tuple (x, y) where x and y are the input values in non-decreasing order. If a is greater than b, return (b, a); otherwise return (a, b).

Task

Use conditional logic to reorder two values when needed and return them as a tuple.

Examples

Swap when first is greater

Input

5, 3

Output

(3, 5)

Since 5 > 3, the returned tuple swaps the values.

Input format

Two numeric arguments a and b (ints or floats).

Output format

Return a tuple (x, y) where x <= y.

Constraints

Do not print; just return the tuple. Maintain exact numeric values and types.

Samples

Sample 1

Input

2, 3

Output

(2, 3)

2 <= 3 so no swap.