WEBVTT

00:00:00.790 --> 00:00:03.190
The following content is
provided under a Creative

00:00:03.190 --> 00:00:04.730
Commons license.

00:00:04.730 --> 00:00:07.030
Your support will help
MIT OpenCourseWare

00:00:07.030 --> 00:00:11.390
continue to offer high quality
educational resources for free.

00:00:11.390 --> 00:00:13.990
To make a donation or
view additional materials

00:00:13.990 --> 00:00:17.880
from hundreds of MIT courses,
visit MIT OpenCourseWare

00:00:17.880 --> 00:00:18.860
at ocw.mit.edu.

00:00:24.930 --> 00:00:26.850
ANA BELL: I have
two functions here.

00:00:26.850 --> 00:00:30.150
One is add, and one is multiply.

00:00:30.150 --> 00:00:34.680
The add function returns
the sum of x plus y.

00:00:34.680 --> 00:00:39.940
And the multiply function just
prints the value of x times y,

00:00:39.940 --> 00:00:42.310
but doesn't return the value.

00:00:42.310 --> 00:00:45.520
Instead, it's going to
implicitly return none

00:00:45.520 --> 00:00:50.680
because we don't have any
return statement inside mult.

00:00:50.680 --> 00:00:53.020
So there are four lines here.

00:00:53.020 --> 00:00:55.240
And the question was how
many total lines of output

00:00:55.240 --> 00:00:57.710
will show up if
you run the code?

00:00:57.710 --> 00:01:02.560
OK, so how many lines
in the console show up?

00:01:02.560 --> 00:01:04.900
So when I do first
add 1, 2, it's

00:01:04.900 --> 00:01:08.900
going to go inside this function
here and say-- it says x is 1,

00:01:08.900 --> 00:01:11.950
y is 2, and return 3.

00:01:11.950 --> 00:01:13.840
So I'm replacing
this line with 3.

00:01:13.840 --> 00:01:15.790
But notice I'm never
printing it out.

00:01:15.790 --> 00:01:19.980
So this line of code will
not print out anything.

00:01:19.980 --> 00:01:25.650
Instead, the next line is
if I print add 2 plus 3,

00:01:25.650 --> 00:01:26.820
then I'm going to get 5.

00:01:26.820 --> 00:01:28.210
And I'm going to print that out.

00:01:28.210 --> 00:01:31.840
So that's one thing
I'm printing out.

00:01:31.840 --> 00:01:35.950
The next line says
multiply 3 and 4.

00:01:35.950 --> 00:01:38.970
So I'm going to go inside my
mult function and say, x is 3,

00:01:38.970 --> 00:01:40.890
y is 4.

00:01:40.890 --> 00:01:45.414
So I'm going to print 12
because 3 times 4 is 12.

00:01:45.414 --> 00:01:47.330
So that's another thing
that gets printed out.

00:01:51.780 --> 00:01:55.610
And I'm not doing anything
with the output-- or sorry, I'm

00:01:55.610 --> 00:01:57.860
not doing anything with
the return from mult.

00:01:57.860 --> 00:02:00.870
So that line is done.

00:02:00.870 --> 00:02:03.160
And the last one
is the trickiest

00:02:03.160 --> 00:02:06.416
and it says print mult 4 and 5.

00:02:06.416 --> 00:02:07.790
So first I'm going
to go in here.

00:02:07.790 --> 00:02:09.229
X is 4, y is 5.

00:02:09.229 --> 00:02:10.810
And I'm printing 20.

00:02:10.810 --> 00:02:14.290
So that's another print.

00:02:14.290 --> 00:02:18.720
And the return of this function
is going to be none, right?

00:02:18.720 --> 00:02:20.925
And the main thing here
is I'm going to print

00:02:20.925 --> 00:02:22.320
at the return of this function.

00:02:22.320 --> 00:02:24.630
So I'm also going
to print out none.

00:02:24.630 --> 00:02:27.250
So that's another one.

00:02:27.250 --> 00:02:29.970
So in total, I'm going to have
four different things printed

00:02:29.970 --> 00:02:33.110
out, the last one
being this none.