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

3rd Jun 2021, 11:28 PM
Ailana
Ailana - avatar
3 ответов
+ 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
3rd Jun 2021, 11:35 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
I have another question. How can I split 1 number into a list? If possible please help.
3rd Jun 2021, 11:49 PM
Ailana
Ailana - avatar
+ 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]
4th Jun 2021, 12:23 AM
ChaoticDawg
ChaoticDawg - avatar