The next question is to write a function that returns this sum of multiples of either one of three or
five between zero and the limited value which we will be providing.
So, for example, if the limit is set to 20, then it should return the sum of numbers.
Three, five, six, nine, 10, 12, 15, 18 and 20, which are multiples of three and five.
So to solve this question, first of all, we will need to get the limited value.
So let's get the limited funding first.
We can simply get it where input, but I am taking it as a random value, let's say integral footprint.
Next, we need to identify if a particular number is ranging in a way that it is a multiple of three
or five.
So how do we find out if a number is a multiple of three or five?
So let's say we have the number X and we want to find out if it is a multiple of five, then we need
to find out the remainder.
So if it is divided by three and the remainder comes out to zero, then it is a multiple of three.
Now, let's check this on a range of.
Twenty
and reflectance.
So here you can see that these numbers, zero three six nine, 12, 15, 18 are divisible by three.
Next, let's do it for five as.
So same condition.
If I got five in place of this, we get zero, five, 10, 15.
So this particular condition decides if the number is divisible by five or three.
So I can simply copy this book here.
Change this to three and four, little or in between.
So this will check for both three and five.
Let's run this again.
So we get this.
Now, what we want to do is we want to get this some of these values so I can simply create a believable
as say.
Is that's the south, so we insulator to zero, and every time the condition is fulfilled, we'll say
is is equal to S plus X.
And finally, once everything is over, then sprint.
Yes.
So we get 78 as a result.
Now, one more thing is that while I run this, I'm not getting 20 because it is skipping to indeed
this counting from zero to 20.
So instead of 20, we need to give it instead of 20.
We need to give it and plus one.
Now, you see 20s also being considered here.
Now, this is a little longer in nature.
We don't want to write too many lines of code.
We can simplify this into a very simple, small and concise line of code so we can convert this in a
way.
So we want to find out some of.
Some numbers which are ranging, let's create a list of her for X in range in plus one.
We want to get X and we want to add them together.
So let's get the value here by just giving 210, because now right now I'm adding everything.
But we have not included this particular condition from here.
So let's pick this condition and paste it here.
So what we are seeing is for X in range and plus one that is numbers ranging from zero to 20.
Check if the number is divisible by three or five.
And if it is completely divisible and the remainder comes out to be zero, simply add all those numbers
together and give me the result.
And here we go.
So this is how we create this.
Now, the question was to create a function which would do this.
So right now, we have created the logic for it.
Now we need to create a function which will do this for us.
So for writing a function, we can simply say there are function neame, let's say Adir.
And it will take numbers.
So see.
And what is this num?
This number will be in.
So what should you do?
It will simply don these values to us.
And if you want to run this, we can simply see print
ad and run added with any number.
So let the number be wati.
And here we have in.
So let's num.
And here we get the result.
So this is how you need to strategize your solution, how you need to write your code.
So first you can write the code in a very simple manner and write your lubes clearly so that your logic
is correct.
Then you can convert it into a list comprehension or any other technique if possible.
And then you added to the definition of the function so that your solution is clear and cutting.