UNIT
1
Python
and Environment IDE
1.1 What is Python?
Python
is a very popular, high-level and general purpose programming language. It was
created by Giudo Van Rossum and released in 1991.
1.2 Applications developed with python:
Python
can be used to create web applications, data analysis application, desktop
applications, machine learning applications, mobile application to mention but
few.
1.3 Tools required before writing python
programs
you must download online (or get a copy of the
installation files from a friend) and install the following tools on your
computer:
-
Translator:
python interpreter
- IDE: pycharm
(although you can use any other IDE or editor) (You can consider using
other IDEs like IntellijIDEA, Spyder or text editor like VS Code (but make sure the
pyton interpreter is installed on your computer))
1.4 File extension of python
Every application software and/or programming
language have its own file extension. The file extension of python is .py,
pronounced as dot py.
1.5 Creating a folder
The purpose of the folder to help you arrange all
your python files and other required libraries in one place.
Let’s create a folder on the desktop:
-
Right click any
empty area on the desktop -> click new -> click folder
-
A new folder
appears, give it a name of your choice e.g python programs
-
If you want to
rename the folder, click the folder, right click, select rename and type the
name you want for your folder.
1.6 Launch Pycharm
-
From the start button, click “type here
to search” box
-
Type Pycharm, it shows the application,
press the enter key or use the mouse to left click it
-
Wait for some seconds for the pycharm to
load
-
pycharm will open automatically when it’s
done.
Accessing the folder you created via PyCharm
If you are working on Pycharm the first time, you
will see screenshot-1, but if you are not just working on Pycharm, you will see
screenshot-2.
Starting with screenshot-1
1.
click on the
open icon
2.
a dialog will
show
3.
there are six
icons at the top of the dialog, (place your mouse pointer on the icon, it will
show tooltip, that is, what each icon represent; first: home directory, second:
desktop directory, etc
4.
click on the
second icon: desktop directory (because this is where we create our folder)
5.
find and click
the name of your folder -> click ok
6.
you will be
prompted with a dialog message-> click trust project
7.
It can also show
another dialog -> click this window -> click new window (if you want to
work on multiple windows)
8.
Pycharm opens a
default file for you called main.py
Starting with screenshot-2
-
If you encounter
screenshot-2, Click file -> click open -> continue from number 2-8 of
starting with screenshot-1 steps
1.7 Interface of Pycharm
- Menu bar (At the topmost part), below the menu bar
is the toolbar, on the left side is the navigation bar, on the right is the
source editor, and at the bottom is the status bar.
1.8 Create your first python file
- Click on the folder name in the navigation bar -> right click -> select new -> select python file from the list of options -> type a name for the file e.g lab_ex_1 -> press enter key -> a new python file called lab_ex_1.py is generated.
1a
1b
The first icon, home icon: is the directory for local disk C:
The second icon, Desktop icon: is the directory for desktop space
2
1.9 Write and run your first python program
In other to display an information, you use the
python output function; which is called print(), you type double quotes into
the parenthesis, then followed by the string of text that you want to display
on the python console. Comment is used to add additional information to your
program, to make comment in python, you use the # hash symbol. When the code
runs, it will not show in the console, that is because the python interpreter
bypass the comment and shows only the executable statements.
NB: if you use another punctuation like curly brace
{ } or square brace [ ] for the print function, it will generate error after
running your code.
#python program to display
caleb university print("established in
21 January, 2008") |
Steps to run your code:
-
Method-1: right
click anywhere in the source editor -> find run followed by the filename of
your program (in our case you will see run lab_ex_1)
-
Method-2: at the
top right of the toolbar, click the down arrow of the config icon, change it to
current file -> click the run icon beside it
-
Method-3: press
shift key and F10 key
-
Method-4: click
run in the menu bar, click run with your current file name
Personally, I do make use of method-1, but you can
use any of the four methods.
OTHERS
1.10 How to change the font size of the source
editor
-> click file -> Settings -> a dialog shows
-> click Editor section -> click
font -> on the right sidebar, enter the font size of your choice to increase
the font size -> click ok
1.11 How to change the font size of menu
options
-> click file -> Settings -> a dialog shows
-> click Appearance & behaviour section -> click appearance -> on
the right sidebar, click the check box of use custom font -> enter the font
size of your choice to increase the font size
1.12 How to use Python online Interpreter to
run your python code
There are many online interpreters that you can use
(www.online-python.com, www.replit.com, www.w3schools.com), but
preferably, I love to use that of www.programiz.com
- You must have internet on your phone
- type python online interpreter on google
- it displays some links, click that of www.programiz.com
- type your first code, click the run button
TIP: if you are using your phone for coding, after you run the code
and you want to go back to the source editor, don’t press the back button, else
all your code in the source editor will disappear, to avoid that, just click
the main.py python file (this is also called python module, a python module is
a python file with the .py extension).
Comments
Post a Comment