You actually already know how to write a simple Python script and store it in a file and then execute
it to streamline you in the previous lecture.
We've got a file that contains a program that simply makes the lid on Tiberio.
Twenty one to blink.
There's not really much more to it.
But in this lecture, I want to show you an example of how you can split your Python programs into multiple
parts so that you can better organize your code, which is particularly useful as your programs become
more complicated and larger.
So can you click on Stop to interrupt the execution of the program?
The LTTE has stopped blinking.
And let's have a look at these two files, which I have stored on the device itself.
The first one is called Arithmetic, and it just contains two functions.
The first one adds two numbers.
The second one subtracts them.
Now, this is the function name and the two parameters.
And again, don't worry about this.
I've got a whole section on Python.
And so the basic Python primer to help you get started with these Python concepts and how to create
functions and classes and how to format your numbers and your output messages.
All this is in Section five, the next one for now, as usual.
Just go along with this.
So this file contains the two functions.
Each function is organized in the same way I've got a print statement and usually format function and
a couple of placeholders here.
Three placeholders to print out the numbers that participate in this calculation.
And the result is just an automatic calculation.
Nothing fancy now in this program here.
And I use underscore arithmetic to why the first thing that I do is to use the import statement or Keywood
to import the let's call it a library, a little library that has two functions in it.
And to do that, I need to use the name of the file without the extension.
So here's the name of the file arithmetic to try to import it.
I just use the name of the file without the extension arithmetic.
And now I'm able to use these two functions in my use arithmetic program.
So I start by creating the two variables and initialize them with a couple of numbers that I came up
with.
And then I'm calling the add numbers that belong to the arithmetic library and I pass the two required
parameters, number one and number two.
And you can see when I run this program by clicking on the button, it just works.
So, of course, these two programs are tiny.
But imagine now that they become much bigger.
The ability to split them into multiple files means that each one of those files is going to be dedicated
to specific purpose and it's going to be simpler to both write and to maintain.
There's a few more things that I want to show you in this section, in the next lecture, I'm going
to show you how to interrupt the running program and then how to set a program to automatically execute
at boot time.
And finally, how to do a bit of debugging on the phone idea for your micro python program, because
remember, you don't really have all of the amazing tools that come with the only available to see Python.