GCD function

``````##
# Compute the greatest common divisor of two positive integers using a while loop.
#
# Read two positive integers from the user
n = int(input("Enter a positive integer: "))
m = int(input("Enter a positive integer: "))
# Initialize d to the smaller of n and m
d = min(n, m)
# Use a while loop to find the greatest common divisor of n and m
while n % d != 0 or m % d != 0:
d=d-1
# Report the result
print("The greatest common divisor of", n, "and", m, "is", d)

``````

This was a solution l found earlier on GCD, today l was trying to rewrite without looking and I realised I had an and instead of or and l don’t understand why they have used or?

I feel there should be and here, but the code doesn’t work

I recommend reviewing the algorithm as it’ll clarify why it makes sense to structure the code a certain way: The Euclidean Algorithm (article) | Khan Academy

I suspect you’re getting turned about by !=
to find `d` we need:
`n % d == 0 and m % d == 0`
so we need to try a new d so long as:
`n % d != 0 or m % d != 0`

See with the or statement, you just need one condition to be true, but there we want a zero remainder for both numbers

sorry for the late reply, my computer was having a problem

thanks