1
00:00:00,690 --> 00:00:07,020
You actually already know how to write a simple Python script and store it in a file and then execute

2
00:00:07,020 --> 00:00:09,450
it to streamline you in the previous lecture.

3
00:00:09,810 --> 00:00:15,540
We've got a file that contains a program that simply makes the lid on Tiberio.

4
00:00:15,540 --> 00:00:17,410
Twenty one to blink.

5
00:00:17,820 --> 00:00:19,710
There's not really much more to it.

6
00:00:19,710 --> 00:00:25,620
But in this lecture, I want to show you an example of how you can split your Python programs into multiple

7
00:00:25,620 --> 00:00:31,980
parts so that you can better organize your code, which is particularly useful as your programs become

8
00:00:32,250 --> 00:00:34,060
more complicated and larger.

9
00:00:34,650 --> 00:00:40,120
So can you click on Stop to interrupt the execution of the program?

10
00:00:40,140 --> 00:00:42,180
The LTTE has stopped blinking.

11
00:00:42,570 --> 00:00:47,390
And let's have a look at these two files, which I have stored on the device itself.

12
00:00:48,180 --> 00:00:53,080
The first one is called Arithmetic, and it just contains two functions.

13
00:00:53,100 --> 00:00:54,600
The first one adds two numbers.

14
00:00:54,630 --> 00:00:56,410
The second one subtracts them.

15
00:00:57,000 --> 00:01:01,590
Now, this is the function name and the two parameters.

16
00:01:01,740 --> 00:01:03,630
And again, don't worry about this.

17
00:01:03,900 --> 00:01:07,980
I've got a whole section on Python.

18
00:01:07,980 --> 00:01:15,360
And so the basic Python primer to help you get started with these Python concepts and how to create

19
00:01:15,360 --> 00:01:20,910
functions and classes and how to format your numbers and your output messages.

20
00:01:21,510 --> 00:01:25,170
All this is in Section five, the next one for now, as usual.

21
00:01:25,170 --> 00:01:26,280
Just go along with this.

22
00:01:26,790 --> 00:01:31,820
So this file contains the two functions.

23
00:01:31,830 --> 00:01:36,870
Each function is organized in the same way I've got a print statement and usually format function and

24
00:01:36,870 --> 00:01:38,230
a couple of placeholders here.

25
00:01:38,340 --> 00:01:42,810
Three placeholders to print out the numbers that participate in this calculation.

26
00:01:42,810 --> 00:01:45,460
And the result is just an automatic calculation.

27
00:01:45,810 --> 00:01:49,230
Nothing fancy now in this program here.

28
00:01:49,230 --> 00:01:56,040
And I use underscore arithmetic to why the first thing that I do is to use the import statement or Keywood

29
00:01:56,370 --> 00:02:02,190
to import the let's call it a library, a little library that has two functions in it.

30
00:02:02,190 --> 00:02:06,350
And to do that, I need to use the name of the file without the extension.

31
00:02:06,870 --> 00:02:11,010
So here's the name of the file arithmetic to try to import it.

32
00:02:11,190 --> 00:02:16,410
I just use the name of the file without the extension arithmetic.

33
00:02:16,860 --> 00:02:22,940
And now I'm able to use these two functions in my use arithmetic program.

34
00:02:23,400 --> 00:02:29,490
So I start by creating the two variables and initialize them with a couple of numbers that I came up

35
00:02:29,490 --> 00:02:29,790
with.

36
00:02:30,060 --> 00:02:38,100
And then I'm calling the add numbers that belong to the arithmetic library and I pass the two required

37
00:02:38,310 --> 00:02:40,620
parameters, number one and number two.

38
00:02:41,370 --> 00:02:48,690
And you can see when I run this program by clicking on the button, it just works.

39
00:02:49,980 --> 00:02:51,900
So, of course, these two programs are tiny.

40
00:02:52,050 --> 00:02:54,390
But imagine now that they become much bigger.

41
00:02:54,600 --> 00:03:00,420
The ability to split them into multiple files means that each one of those files is going to be dedicated

42
00:03:00,420 --> 00:03:04,800
to specific purpose and it's going to be simpler to both write and to maintain.

43
00:03:05,780 --> 00:03:10,910
There's a few more things that I want to show you in this section, in the next lecture, I'm going

44
00:03:10,910 --> 00:03:17,300
to show you how to interrupt the running program and then how to set a program to automatically execute

45
00:03:17,300 --> 00:03:18,580
at boot time.

46
00:03:18,980 --> 00:03:25,760
And finally, how to do a bit of debugging on the phone idea for your micro python program, because

47
00:03:25,760 --> 00:03:32,330
remember, you don't really have all of the amazing tools that come with the only available to see Python.
