Android & iPhone apps are coming soon. Log in for a plan and reminders made for you →

Coding basics · 15 of 20

Greatest common divisor

Return the largest number that divides both a and b (both non-negative, not both 0).

What you need

Python can swap or update two variables at once: the right side is worked out first, then assigned.

a, b = 3, 5
a, b = b, a    # now a = 5, b = 3

Examples

Input a = 12, b = 18

Output 6

Input a = 7, b = 5

Output 1

Input a = 10, b = 0

Output 10

Your code · Python

Stuck?