Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 12

Swap Values If First Greater

Easy

10 minute session

Summary

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

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)

Explanation

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 input 0

2, 3

Sample output 0

(2, 3)

Explanation 0

2 <= 3 so no swap.

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.

03:51 AM

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