The program below was more precise and shorter than mine, and thus more appealing. I understand mod (%), but the rest of the syntax on the line noted is confusing me. Does anyone know what this syntax is called or how it works?
The problem asked to create a function to find the greatest common divisor (gcd) for two integers, which is the largest number that divides both numbers without a remainder.
For example, the gcd of 20 and 12 is 4.
def gcd(x, y):
while y != 0:
(x, y) = (y, x % y) ## What is happening here? What's this syntax called?
return x
Link to where I found this program: How to calculate a mod b in python?
Thank you so much for your help!