00:01
The question asks us to write a python function to find out whether a number is divisible by the sum of all of its digits.
00:09
If it is divisible by all its digits, then we return true, otherwise we return false.
00:14
The number is less than or equal to zero.
00:16
We have invalid input.
00:17
So let's go ahead and write the function, define, we'll call it is divisible.
00:27
And we input a number.
00:32
If a number is less than then or equal to zero, return invalid input.
00:45
That's just the beginning.
00:46
Then we'll have a boolean flag.
00:49
We'll say number finished and we'll call that false.
01:00
Then while number finished is, sorry, we'll call it true.
01:08
And then while number finished is true, we're gonna loop through.
01:11
So essentially the format of this, or the, the logic of this algorithm we're going to write here is simply we're going to go through each digit in the pitha, in the number, right, from right to left.
01:26
We're going to add them all up and store them into a number.
01:29
And then at the very end, after we reach the very end, we're going to quit out of the while loop, and then we're going to see if number is divisible by whatever the sum was.
01:37
And if the number mod sum equals 0, which means the number is divisible by the sum, then we're going to return true, otherwise we're going to return false.
01:49
So first of off, before this y loop here, we're going to have to have a sum, which equals 0.
01:56
Then we'll have our y loop, and our y loop will say number finished.
02:03
And on the inside we'll do sum plus equals our number mod 10 so what this does is it's essentially going to add the very last digit so let's say we have 7172 um it's going to so 7172 mod 10 will return 2 so it's going to add 2 to the sum then what we're going to do is numb divide equals 10 so after we do that so it's going to add 2 to add 2 to the sum so it's going to add 2 to the sum and to the sum, then 7172 divided by 10 gives us 717...