Issue
First-Timer here 🙂
The very simple function geome(x) gives no output, eventhough the exact same code works fine outside of the function (see "z = list …").
What am I doing wrong?
Would very much appreciate some help or hintsThank you.
from operator import truediv
x = [1, 2, 4, 8, 16]
z = list(map(truediv, x[1:], x[:-1])) # This Works perfectly fine! >>> Geometric
if all(num == z[0] for num in z):
print('Geometric')
def geome(x):
z = list(map(truediv, x[1:], x[:-1]))
if all(num == x[0] for num in z):
print('Geometric')
geome(x) # Doesn't work, even though it is the same code as above, only inside of a function. >>>
Solution
Your geome
implements something different to what you have outside. In the if
clause you changed z[0]
to x[0]
, so geome
should be like this instead:
def geome(x):
z = list(map(truediv, x[1:], x[:-1]))
if all(num == z[0] for num in z):
print('Geometric')
Answered By – molinav
Answer Checked By – Clifford M. (BugsFixing Volunteer)