Lesson 4
How to Create Simple Program with File
Liam
How to Create Simple Program with File
Emma
Hey Liam.
It's not what I expected.
Liam
Why?
Emma
When I entered the code into the IDLE, it just displayed the output below it.
Liam
Because we've been working in a "shell window", so we just see the output below the code.
IDLE is called "Interactive Interpreter" because you type code and it's done right away.
Emma
But this is troublesome because I have to instruct each time.
Liam
That's true.
Ordinary programs are created in a different way.
We write the whole program in a file in advance and then run it.
Emma
It's kinda like programming.
Liam
Let’s Create Simple Greeting Program!
Now, let's write the program in a file and let it run.
There are three main steps.
1. Create a new file and write a program.
2. Save the file.
3. Run the program.
Emma
OK! There are three steps.
Liam
So, let's start by creating a new file.
Select “New File” from the File menu.
Then a window to enter the program will appear.
We will enter the program here.
Emma
OK. I opened the new window to enter the program.
Liam
Next, we will enter the program.
Let's enter the following two-line program.
print("Hi, Emma!")
print("How are you?")
Emma
OK. I entered the program in the file.
Liam
Next, save the file.
Select “Save” from the File menu.
Enter a file name in the Save As field, select a save location, and click the Save button.
The extension of a Python file is “dot py", so add “dot py" to the end of the name, for example hello dot py.
Emma
What is the extension?
Liam
There are various types of files on your computer.
In order to distinguish the type, the distinguishing symbol at the end of the file name is called "extension".
Emma
I understand that the extension is a symbol to indicate the type of file.
Liam
Exactly!
For Python, add “dot py" as the extension at the end of the file name.
Now, let's run the program we saved!
Select “Run Module” from the Run menu.
Then Python will show you a greeting.
Emma
Yay! Python greeted me!
But I thought it would show up just below the program I wrote, but it shows up in a different window.
Liam
That's right.
The program file is where you write the program, and it's separate from the output.
The program is written in "file" and the program is executed in "shell window".
Emma
I understand very well.
By the way, how do I open the saved program again?
Liam
All you have to do is select the saved file and open it.
First, let's select “Open” from the File menu.
Next, select File from the saved location and click the Open button.
Emma
The saved file opened properly.
In this lesson, I learned how to create and run a program file.
Liam
Well done.
On this page of the site you can watch the video online #4 Python Playground: Program with File | Computer Programming & Coding for Kids & Beginners with a duration of hours minute second in good quality, which was uploaded by the user Animate U | Python Playground 07 October 2020, share the link with friends and acquaintances, this video has already been watched 6,224 times on youtube and it was liked by 71 viewers. Enjoy your viewing!