Daily Coding Challenge - GCD

Tell us what’s happening:

Hey, hope it’s not too much of a bother but I’ve seen my return is print correctly for this project , but I can’t seem to find a way to make it return in a way that the challenge accepts it in python. I know I’m probably missing something just trivial but if you could let me know that would be amazing! Thank You!

Your code so far

def gcd(x, y):
    if x>y:
        z=x
    if y>x:
        z=y
    else:
        z=x
    x_divisors = []
    y_divisors = []
    common_divisor = []
    for integers in range(1,z,1):
        if x%integers == 0:
            x_divisors.append(str(integers))
    for integers in range(1,z,1):
        if y%integers == 0:
            y_divisors.append(str(integers))
    print( )
    if len(y_divisors) >= len(x_divisors):
        for divisor in y_divisors:
            if divisor in x_divisors:
                common_divisor.append(str(divisor))
    else:
        for divisor in x_divisors:
            if divisor in y_divisors:
                common_divisor.append(str(divisor))
    greatest_common_divisor= max(common_divisor)
    print(greatest_common_divisor)
    return greatest_common_divisor
gcd(654, 456)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0

Challenge Information:

Daily Coding Challenge - GCD
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-11-15

you are returning a string, don’t you think that could be an issue?

1 Like

Figured it out, looks like I still hadn’t changed the type of my answer from string back into integer!!!

1 Like

Thank you so much!!!

using Euclid’s algorithm is a lot more easier and simpler

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

Definitely would have been faster to code, where did you end up finding that method?

Thanks for coming across so warmly. I was just wondering if you could tell me where you came across that algorithm :slight_smile:

A quick search (DuckDuckGo) for “algorithm gcd” returns :