I am creating a program to figure out the highest number of decimals in a list of numbers. Basically, a list with [123, 1233]
would return 4 because 1233 has four numbers in it and it is the largest. Another example would be that [12, 4333, 5, 555555]
would return 6 because 555555 has 6 numbers.
Here is my code.
def place(listy):
if len(listy) == 1:
decimal = len(str(listy[0]))
print(decimal)
else:
if len(str(listy[0])) >= len(str(listy[1])):
new_list = listy[0:1]
for i in listy[2:]:
new_list.append(i)
place(new_list)
else:
place(listy[1:])
Now, when I use print(decimal)
it works, but if I change print(decimal)
to return decimal
, it doesn't return anything. Why is this? How do I fix this? I have come across these return statements which doing run a lot of times. Thanks in advance!