19 May First Python Program (Script Mode)
In this lesson, we will learn how to run our first Python program using script mode. Previously we saw how to run python program using Interactive Mode.
Create a folder in any of your directory. Here all the python programs will get stored. We have created a folder, MyPython and the directory is D:
1 2 3 |
D:\MyPython |
Now you need to create a .py extension file to save your code in it.
But, before creating a text file with the extension .py, let us set the folder (MyPython) path.
Set Path for project folder in Python
To set the above shown folder path, go to Start, and type Environment Variables, click Edit the system Environment Variables.
Now, you will reach the System Properties dialog box.
Click Environment Variables, then a new dialog box will open.
Click Edit after selecting Path variable or you can also double click Path and add the D:/MyPython path in it like the following:
Press Save for all the three dialog boxes and our folder path will set successfully.
Now create a text file and save it as .py, since python code gets saved in the same extension. Our file is named, studyopedia.py and saved in the same folder, MyPython,
Add the following demo code and save it,
1 2 3 4 5 |
print ("Welcome to Studyopedia!") print ("First Python 3 program!") print ("Script Mode!") |
Now go to Command Prompt and reach the following path,
Now type the following and press enter to get the output,
1 2 3 |
python studyopedia.py |
The following is the output,
We learned how to run our first program.
In the upcoming lessons, we will follow the same Script Mode approach.
No Comments