def gcd(n,m): # check for the smallest number divisor= min(n,m) print (divisor) #Finding the greatest divisor while n % divisor != 0 and m % divisor != 0: divisor -= -1 print (divisor) return divisor return m return n print(gcd (24,32))
I am getting this error here, please help
return hands back data to the caller/function call, which signals that the function is done executing, so we can only return a single value.
this single value can of course be a container (dictionary, list) containing multiple values
so what should l do, I use one return statement and the rest a print statement?
that is up to you, I have no idea what the task/assignment is
one return statement for sure
I don’t see the value of returning
m, these values do not change. Seems returning divisor should be sufficient
def foo(): return 1, 2 a, b = foo() print(a, b)
Wouldn’t this be considered returning multiple values?
no, python wraps the return values in a container/wrapper:
def foo(): return 1, 2 print(type(foo()))
I included this in my answer:
Ahh, okay. I thought you were meaning:
def foo(): return [1, 2]
Good to know.
any container type (dict, list, tuple) will do, this:
def foo(): return 1, 2
is the same as:
def foo(): return (1, 2)
Its still one return value (a tuple) containing multiple values
the latter being somewhat more explicit, but you can still see here:
a, b = foo()
that you are unpacking the values, so clearly they where packed
thanks got my answer