- #1
Taylor_1989
- 402
- 14
- TL;DR Summary
- I am having an issue compiling a solution for a leetcode problem, which compiles fine on an online compiler.
I just submitted a solution for a leetcode problem, displayed below.
My solution is broken into three separate functions as shown below.
On the site : https://www.programiz.com/python-programming/online-compiler/
This complies fine when I run there example case and get the same output.
However, when I copy the code into leetcode I get the following:
And the output when compiled is :
But I can't seem to understand why it works fine in the online compiler but not there. Any ideas?
A self-dividing number is a number that is divisible by every digit it contains.
For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.
Also, a self-dividing number is not allowed to contain the digit zero.
Given a lower and upper number bound, output a list of every possible self dividing number, including the bounds if possible.
Example 1:
Input:
left = 1, right = 22
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
The boundaries of each input argument are 1 <= left <= right <= 10000.
My solution is broken into three separate functions as shown below.
Python:
def Checker(dig, number):
"""
Purpose: Function check if the given number is divisible by each
digit in the given number.
Parameters:
dig (int) : Last digit of the given number i.e if n=128 then the first digit
to be compared would be 8, second 2 etc per iteration.
number (int) : Number to check if self divisible.
Returns :
bool : True or False. Ture if the number is divisible by the digit and False otherwise.
"""
if number==0:
return(False)
else:
return(dig !=0 and dig % number==0)def All_Divsable(n):
"""
Purpose: Function take the give number n and then take the end digit and checks if the number is divisible by the end didigt and repeats until . temp ==0.
Parameters:
n (int) : number to be check if self divisible
Returns :
bool : True or False. Ture if the number is sefl divisable False otherwise."""
temp=n
while temp > 0:
temp=temp % 10
if (Checker(n,temp)==False):
return(False)
temp //=10
return(True)
def res(left, right):
L=[]
for i in range(left,right+1):
if All_Divsable(i)==True:
L.append(i)
return(L)
This complies fine when I run there example case and get the same output.
Output : [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 21, 22]
However, when I copy the code into leetcode I get the following:
Leetcode:
class Solution(object):
def selfDividingNumbers(self, left, right):
def Checker(dig, number):
"""
Purpose: Function check if the given number is divisible by each
digit in the given number.
Parameters:
dig (int): Last digit of the given number i.e if n=128 then the first digit
to be compared would be 8, second 2, etc per iteration.
number (int): Number to check if self divisible.
Returns :
bool : True or False. Ture if the number is divisible by the digit and False otherwise.
"""
if number==0:
return(False)
else:
return(dig !=0 and dig % number==0)
def All_Divsable(n):
"""
Purpose: Function take the give number n and then take the end digit and checks if the number is divisible by the end didigt and repeats until . temp ==0.
Parameters:
n (int) : number to be check if self divisible
Returns :
bool : True or False. Ture if the number is sefl divisable False otherwise."""
temp=n
while temp > 0:
temp=temp % 10
if (Checker(n,temp)==False):
return(False)
temp //=10
return(True)
L=[]
for i in range(left,right+1):
if All_Divsable(i)==True:
L.append(i)
return(L)
And the output when compiled is :
But I can't seem to understand why it works fine in the online compiler but not there. Any ideas?