Eng Ali Abu Harb Lab1
Eng Ali Abu Harb Lab1
Lab1
Introduction to Python
–––
Compiler
A compiler is defined as a computer program that is used to convert high level instructions or
language into a form that can be understood by the computer. Since computer can understand only
in binary numbers so a compiler is used to fill the gap otherwise it would have been difficult for a
human to find info in the 0 and 1 form.
Interpreter
The programs created in high level languages can be executed by using two different ways. The
first one is the use of compiler and the other method is to use an interpreter. High level instruction
or language is converted into intermediate from by an interpreter. The advantage of using an
interpreter is that the high level instruction does not goes through compilation stage which can be
a time consuming method. So, by using an interpreter, the high level program is executed directly.
That is the reason why some programmers use interpreters while making small sections as this
saves time.
Difference between compiler and interpreter
• A complier converts the high level instruction into machine language while an
interpreter converts the high level instruction into an intermediate form.
• List of errors is created by the compiler after the compilation process while an
interpreter stops translating after the first error.
The high-level data types allow you to express complex operations in a single
statement.
Python programs must be written with a particular structure. The syntax must be correct, or the
interpreter will generate error messages and not execute the program.
Listing 1.1 (hello.py) is one of the simplest Python programs that does something:
Installing Python
Pycharm 2019 : go to official website and download the last version from there
https://www.jetbrains.com/pycharm/download/
Installing Python is an easy task, after download file, we simply double-click this icon to open
the Python.
And then check box ( Add puthon to path) and click Install Now
- After Setup was successful , Press Close.
The following icon appears in the programs , from now on we simply double-click this icon to
open the Python IDE, it is a simple IDE.
Invoking the interpreter without a script parameter begins process of writing and executing
the lines of Python code one by one until the script is finished. When the script is finished,
the interpreter is no longer active.
This becomes impractical for larger programs, so an alternative exists. In batch mode, we first
write all the lines in a separate file, and then run them all at once.
Let us write a simple Python program in a script. Python files have extension .py.
In the shell window, click File → New File
A new window appears, without the Python prompt >>>
When you’re ready, click Run → Run Module (or just press the function key F5). IDLE will first
ask you to save the file, then it will execute it, with the results shown back in the shell window
And the output will be like this after running the program
In our lab we will use another IDE (Integrated development environment) called
PyCharm Community Edition:
First , be sure Python interpreter is downloaded and installed on your computer , then double-
click the PyCharm Download file then click Next >
Now the installation is done , Go to start and search on PyCharm>>
If this the first time that you run the programe , this window will appear , so you should choose the
second option :
Right click on project name( in our example is Lap1_Alex) and New>>Python File ,then write the name
of your file, for example test and press enter.
PyCharm WorkSpace:
After you write script code click Run → Run “script file” (or press the function key shift
+F10) .
Also , you can run Python shell through PyCharm by click Tools → Python Console
Lab work 1 :
Exercises:
1) What is an interpreter?
2) What is necessary to execute a Python program?
3) Write a program that displays “Welcome to Python”, “Welcome to Engineering”, and
“Programming is fun” (Display three messages).
Note :
Write your homework in Word Document and then send it to me via this Email :
aliharb@protonmail.com