Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,540 --> 00:00:08,100
So another day, another challenge, right, guys, in this challenge, we proceed with practicing functions.
2
00:00:08,520 --> 00:00:15,180
And the reason for that, for why I so much insist on practicing more and more exercises with functions,
3
00:00:15,390 --> 00:00:19,380
is because this topic is actually so important.
4
00:00:19,710 --> 00:00:23,130
And it will guide you during most of your programming career.
5
00:00:23,700 --> 00:00:26,480
So pay close attention and let's go.
6
00:00:26,730 --> 00:00:32,400
And what I want you to do in this challenge is simply to write a function that will receive a number
7
00:00:32,400 --> 00:00:33,750
of an integer type.
8
00:00:34,110 --> 00:00:37,490
And then the function is going to calculate its factorial.
9
00:00:37,650 --> 00:00:43,650
And just a quick reminder, for those of you who is not familiar with water, if Victoria really means
10
00:00:43,650 --> 00:00:50,520
and how it's calculated, the factorial of a given number is calculated by multiplying all the natural
11
00:00:50,520 --> 00:00:53,700
numbers from one up to the given number.
12
00:00:53,730 --> 00:01:01,440
So a factorial of NUM equals two one multiplied by two by three and so on up to the multiplication by
13
00:01:01,500 --> 00:01:02,010
NUM.
14
00:01:02,040 --> 00:01:02,440
All right.
15
00:01:02,460 --> 00:01:05,740
In this case, we specified D as M name equals to M.
16
00:01:05,940 --> 00:01:12,300
So for example, if you have a m to calculate the factorial of three equals two, one multiplied by
17
00:01:12,300 --> 00:01:16,680
two multiplied by three, which is a total of just six.
18
00:01:16,800 --> 00:01:23,370
And if you have to calculate the factorial of a number five, then you will say that eight equals two,
19
00:01:23,370 --> 00:01:30,120
one by two by three by four by five, which is a total of one hundred and twenty.
20
00:01:30,250 --> 00:01:30,720
Whoops.
21
00:01:30,900 --> 00:01:32,490
Here I have only six.
22
00:01:32,730 --> 00:01:36,000
That should be fixed to one hundred and twenty.
23
00:01:36,690 --> 00:01:40,410
So basically you've got the point hand and that's my mistake.
24
00:01:40,410 --> 00:01:41,340
I will fix it up.
25
00:01:41,400 --> 00:01:47,880
So basically you multiply all the numbers from one, two, three up to the specified number to find
26
00:01:47,970 --> 00:01:49,050
Edes factorial.
27
00:01:49,410 --> 00:01:52,140
And then the function is going to return.
28
00:01:52,170 --> 00:01:52,860
The result?
29
00:01:52,890 --> 00:01:56,300
It will calculate the factorial and return the result.
30
00:01:56,350 --> 00:01:59,690
And not printed to the screen, but rather it will return it.
31
00:01:59,880 --> 00:02:06,090
So there we can check with the main function that it actually works as we expected it to work.
32
00:02:06,360 --> 00:02:10,410
And that will basically bid for these function.
33
00:02:10,410 --> 00:02:18,150
And one thing that I would like you to notice is that if then if a given number is going to be a negative
34
00:02:18,150 --> 00:02:26,310
number, then the function will return minus one, because we cannot calculate a factorial for a negative
35
00:02:26,310 --> 00:02:26,880
number.
36
00:02:27,000 --> 00:02:31,440
And these minus one will specify that something something was wrong there.
37
00:02:31,950 --> 00:02:36,000
And we will know how to treat it later on.
38
00:02:36,150 --> 00:02:37,440
So good luck, guys.
39
00:02:37,490 --> 00:02:40,350
Give it a try and I'll see you in the next video.
3748
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.