Nov-09-2020, 12:27 AM
Hello, I'm on Problem 1 from this website: https://courses.cs.washington.edu/course...part1.html
The premise is simple, but I'm having difficulties with the syntax.
The objective is to build a function with two inputs, n & m, and returns the digits within n that are divisible by m.
For example, if n = 1234567 & m = 2, then the output would be 2, 4 & 6.
And for any 0's in n, it is always divisible and shown in the output.
For example, if n = 1500000 & m = 5, then the output would be 0 & 5.
Lastly, if m = 0, then the output will always be 0.
E.g., n = 22 & m = 0, output = 0.
My strategy is to allow n to be a tuple, and create a for loop that goes over each digit of n.
For each digit, it will be divided by m to see if it's divisible, but it'll first check to see if that digit is 0.
I haven't included what happens when m = 0, but what I have so far gives me a TypeError that 'int' object is not iterable.
The premise is simple, but I'm having difficulties with the syntax.
The objective is to build a function with two inputs, n & m, and returns the digits within n that are divisible by m.
For example, if n = 1234567 & m = 2, then the output would be 2, 4 & 6.
And for any 0's in n, it is always divisible and shown in the output.
For example, if n = 1500000 & m = 5, then the output would be 0 & 5.
Lastly, if m = 0, then the output will always be 0.
E.g., n = 22 & m = 0, output = 0.
My strategy is to allow n to be a tuple, and create a for loop that goes over each digit of n.
For each digit, it will be divided by m to see if it's divisible, but it'll first check to see if that digit is 0.
I haven't included what happens when m = 0, but what I have so far gives me a TypeError that 'int' object is not iterable.
def count_divisible_digit(tuple(n), m): for i in n[i]: if value = 0: result.append(value) elif (value/m = int) and (value % m = 0): result.append(value) else: return null Print(result)
def count_divisible_number(n, m): x=tuple(n) for i in len(x): if x[i] == 0: result.append(value) elif x[i] % m == 0 & x[i] != 0: result.append(value) return result