Just starting with Python and doing some challenges, this one on Collatz numbers.
I am stuck at the start however, where the range that I am passing to the collatz
method is not iterating over the given range.
What am I missing here?
def collatz(number):
for i in number:
if i % 2:
return i // 2
else:
return 3 * (i + 1)
try:
print(collatz(range(0,10)))
except ZeroDivisionError:
print("Zero Division")
except TypeError:
print "Type Error"
for i in range(0,10):
print(collatz(i))