0% found this document useful (0 votes)
54 views18 pages

Eng Ali Abu Harb Lab1

Eng. Ali Abu Harb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views18 pages

Eng Ali Abu Harb Lab1

Eng. Ali Abu Harb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

‫‪Islamic University of Gaza Faculty of‬‬

‫‪Engineering Computer Engineering‬‬


‫‪Dept.‬‬

‫‪Introduction to Computers Lab‬‬


‫ــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

‫‪Lab1‬‬

‫‪Introduction to Python‬‬

‫–––‬

‫‪Eng. Ali Abu Harb‬‬


Introduction

- Python is a high-level, object-oriented programming language created by Guido


van Rossum.
- It is used for software development at companies and organizations such as
Google, Yahoo, and NASA, it is designed to be highly readable.
- It has a very easy-to-use and simple syntax, making it the perfect language for
someone trying to learn computer programming for the first time.
- It’s is an interpreted language. Interpreter is a program that converts the high-
level program we write into low-level program that the computer understands.
- There are two major Python versions, Python 2 and Python 3. Python 2 and 3 are
quite different.
- Programs written in Python are typically much shorter than equivalent C, C++, or
Java programs, for several reasons:

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.

• Before execution, entire program is executed by the compiler whereas after


translating the first line, an interpreter then executes it and so on.

• 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.

Statement grouping is done by indentation instead of beginning and ending


brackets { } .
No variable or argument declarations are necessary, first example shows this.

Writing a Python Program

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

Note: here are the softwares that we will need:


Puthon 3.7.4 : go to official website and download the last version from there
https://www.python.org/downloads/

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.

The command window, shell, appears:


There two different modes of programming:

- Interactive Mode Programming

Invoking the interpreter without passing a script file as a parameter.


We can see the prompt >>>, where we can write and execute Python code in interactive mode.
At the prompt, enter your first command.

- Script Mode Programming (batch mode):

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 :

Then , agree with policy of this software and click continue


Here, choose the favorite theme and click next, and click start using pycharm in the second screen.
Click on Create new project >
Select location project and its name, and sure you select correct Python interpret
Then click on Create.

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).

4) Write a program that displays the following pattern? (Display a pattern).

Note :
Write your homework in Word Document and then send it to me via this Email :
aliharb@protonmail.com

And named the file like this (yourFirstName_yourNumber_LabNumber)


For example : (Ali_120141028_Lab1)

Reference : Eng. Nour Eldadah

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy