0
Why is there a ZERO ERROR????
Here is my function and I don't know why my code outputs an error... Please help if possible. Here is my code: def min_permutation(n): if n == 0: return 0 elif 0 in n: return n else: pass
3 Réponses
+ 3
If n is a number;
elif 0 in n:
Is invalid, because a number is not iterable.
Converting to a str() can resolve the issue.
elif '0' in str(n):
Then your current else statement isn't needed and could be removed.
def min_permutation(n):
if n == 0:
return 0
elif '0' in str(n):
return n
+ 1
I have another question. How can I split 1 number into a list? If possible please help.
+ 1
Do you mean a number such as
n = 4321
Into a list like
n = [4, 3, 2, 1]
???
If so,
n = 4321
n = list(str(n)) # n is now [4, 3, 2, 1]