0% found this document useful (0 votes)
1 views17 pages

UNIT-1 Introduction To Python Programming

This document serves as an introduction to Python programming, covering its history, features, and applications. It explains the significance of programming, the advantages of learning Python, and compares Python with other programming languages. Additionally, it highlights Python's major uses in various industries and its suitability for beginners.

Uploaded by

Ahmed Abdalla
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)
1 views17 pages

UNIT-1 Introduction To Python Programming

This document serves as an introduction to Python programming, covering its history, features, and applications. It explains the significance of programming, the advantages of learning Python, and compares Python with other programming languages. Additionally, it highlights Python's major uses in various industries and its suitability for beginners.

Uploaded by

Ahmed Abdalla
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

UNIT ONE

Introduction to Python Programming

This unit helps you by covering the following objectives:

 What is programming?
 Why learn programming?
 History of python
 Why python?
 Python Features
 Comparing python with other languages
 Applications of python
 Major uses of python
 List of organizations using python(sector-wise)
 Flavors of Python
 Python Frameworks
 Downloading and installing python
 Integrated Development Environment
 Program execution
 Programming with python
 Glossary
 Exercises

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 1 of 17


UNIT-I : Introduction to Python Programming
What is programming?
In simple words, programming means telling a computer to do something. Computers are dumb
machines. They don’t know how to do anything. You have to tell them everything, and you have to get all
the details right.
But if you give them the right instructions, they can do many wonderful and amazing things.
A computer program is made up of a number of
instructions. Computers do all the great things they
do today because a lot of smart programmers wrote
programs or software to tell them how. Software just
means a program or collection of programs that run
on your computer, or sometimes on another
computer, which yours is connected to, like a web
server.
Why learn programming?
Even if you don’t become a professional programmer (most people don’t), there are lots of reasons to
learn programming:
 The most important is because you want to! Programming can be very interesting and rewarding,
as a hobby or a profession.
 If you’re interested in computers and want to know more about how they work and how you can
make them do what you want, that’s a good reason to learn about programming.
 Maybe you want to make your own games, or maybe you can’t find a program that does exactly
what you want or need it to do, so you want to write your own.
 Computers are everywhere these days, so there’s a good chance you’ll use computers at work, at
school, or at home—probably all three. Learning about programming will help you understand
computers better in general.
History of Python:
The name Python was selected from "Monty Python’s Flying Circus" which was a British sketch comedy
series created by the comedy group Monty Python and broadcast by the BBC from 1969 to 1974.
Python was created in the early 1990s by Guido van Rossum at the National Research Institute for
Mathematics and Computer Science in Netherlands.
Python was created as a successor of a language called ABC (All Basic Code) and released publicly
in1991. Guido remains Python’s principal author, although it includes many contributions from active
user community.
Python is derived from many other languages, including ABC, Modula-3, C, C++, Algol-68,
Smalltalk, and UNIX shell and other scripting languages.
Between 1991 and 2001 there are several versions released, current stable release is 3.2. In 2001 the
Python Software Foundation (PSF) was formed, a non-profit organization created specifically to own
Python-related Intellectual Property. Zope Corporation is a sponsoring member of the PSF.
What is Python?
 Python is an interpreted uncomplicated and robust programming language that delivers both the
power and complexity of traditional compiled languages along with the ease-of-use of simpler
scripting and interpreted languages.
 Python is a free, open-source, general-purpose, interpreted, and powerful scripting language for
Web applications. It is an easy yet powerful programming language that provides structure and
support for large applications as well as the power and complexity of traditional high-level
languages.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 2 of 17


 Python is a high-level, interpreted, interactive and object-oriented scripting language.
 Python is Beginner's Language: Python is a great language for the beginner programmers and
supports the development of a wide range of applications from simple text processing to WWW
browsers to games.
Python Versions:
There are two main branches of Python currently. Python 2.x and Python 3.x. Python 3.x break backward
compatibility with previous releases of Python. It was created to correct some design flaws of the
language and make the language more clean. The last release of Python 2.x is 2.7.18(April 20, 2020), and
the most recent release of Python 3.x is 3.13.2. (February 04, 2025)
Comparison between python 2 and python 3:
In Python 3 the print statement has been replaced with a print ( ) function, with keyword arguments to
replace most of the special syntax of the old print statement.

Python 2 Python 3

>>> print "Hello World" >>> print("Hello World")

Hello World Hello World

>>> #print a newline >>> #print a newline,

>>> print >>> #using parentheses

>>> print()

>>> print "6/3 =", 6/3 >>> print("6/3 =", 6/3)

6/3 = 2 6/3 = 2.0

>>> print "6//3 =", 6//3 >>> print("6//3 =", 6//3)

6//3 = 2 6//3 = 2

>>> print "6/3.0 =", 6/3.0 >>> print("6/3.0 =", 6/3.0)

6/3.0 = 2.0 6/3.0 = 2.0

>>> print "6//3.0 =", 6//3.0 >>> print("6//3.0 =", 6//3.0)

6//3.0 = 2.0 6//3.0 = 2.0

>>> >>>

Why Python programming?


With all the programming languages to choose from (and there are a lot!), why did we pick Python for
beginner programmer/freshman student?
Here are a few reasons:
 Python was created from the start to be easy to learn. Python programs are about the easiest to
read, write, and understand of any computer language that we have seen.
 Python is free. You can download Python—and many, many fun and useful programs written in
Python—for free.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 3 of 17


 Python is open source software. Part of what open source means is that any user can extend
Python (create things that let you do more with Python, or do the same things more easily). Many
people have done this, and there is a large collection of free Python stuff that you can download.
 Python isn’t a toy. Although it’s very good for learning programming, it’s also used by thousands
of professionals around the world every day, including programmers at institutions like NASA and
Google. So once you learn Python, you don’t have to switch to a “real” language to make “real”
programs. You can do a lot with Python.
 Python runs on different kinds of computers. Python is available for Windows PCs, Macs, and
computers running Linux. Most of the time, the same Python program that works on your
Windows PC at home will work on the Linux PC at your college. You can use this book with
virtually any computer that has python.
 Python has shined as a tool that allows programmers to get more done with less effort. It is
deliberately optimized for speed of development—its simple syntax, dynamic typing, lacks of
compile steps, and built-in toolset allow programmers to develop programs in a fraction of the
time needed when using some other tools. The net effect is that Python typically boosts developer
productivity many times beyond the levels supported by traditional languages.

Main features of Python:


Although it has been around for well over fifteen years, some feel that Python is still relatively new to the
general software development industry. We should, however, use caution with our use of the word
"relatively," as a few years seem like decades when developing on "Internet time."
When people ask, "What is Python?" it is difficult to say any one thing. The tendency is to want to blurt
out all the things that you feel Python is in one breath. what are some of those features? For your sanity,
we will elucidate each here ... one at a time.
High Level: It seems that with every generation of languages, we move to a higher level. Assembly was a
godsend for those who struggled with machine code, then came FORTRAN, C(middle level language),
and Pascal, which took computing to another plane and created the software development industry.
Through C came more modern compiled languages, C++ and Java. And further still we climb, with
powerful, system-accessible, interpreted scripting languages like Tcl, Perl, and Python.
Each of these languages has higher-level data structures that reduce the "framework" development time
that was once required. Useful types like Python's lists (resizable arrays) and dictionaries (hash tables) are
built into the language. Providing these crucial building blocks in the core language encourages their use
and minimizes development time as well as code size, resulting in more readable code.
Easy-to-learn: Python has relatively few keywords, simple structure, and a clearly defined syntax. This
allows the student to pick up the language in a relatively short period of time.
Easy-to-maintain: Python's success is that its source code is fairly easy-to-maintain in terms of memory.
A broad standard library: One of Python’s greatest strengths are the bulk of the library is very portable
and cross-platform compatible on UNIX, Windows and Macintosh.
Interactive Mode: Support for an interactive mode in which you can enter results from a terminal right to
the language, allowing interactive testing and debugging of snippets of code.
Extendable: You can add low-level modules to the Python interpreter. These modules enable
programmers to add to or customize their tools to be more efficient.
Databases: Python provides interfaces to all major commercial databases.
GUI Programming: Python supports GUI applications that can be created and ported to many system
calls, libraries and windows systems, such as Windows MFC, Macintosh and the X Window system of
UNIX.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 4 of 17


Object-Oriented: Python is an object-oriented language, from the ground up. Its class model supports
advanced notions such as polymorphism, operator overloading, and multiple inheritance; yet, in the
context of Python’s simple syntax and typing, OOP is remarkably easy to apply. In fact, if you don’t
understand these terms, you’ll find they are much easier to learn with Python than with just about any
other OOP language available.
Portable: Python can run on a wide variety of hardware platforms and has the same interface on all
platforms the standard implementation of Python is written in portable ANSI C, and it compiles and runs
on virtually every major platform currently in use. For example, Python programs run today on everything
from PDAs to supercomputers. As a partial list, Python is available on:
 Linux and Unix systems  PDAs running Palm OS, Pocketpc,
 Microsoft Windows and DOS and Linux
 Mac OS (both OS X and Classic)  Cell phones running Symbian OS
 BeOS, OS/2, VMS, and QNX and Windows Mobile
 Real-time systems such as works  Gaming consoles and iPods
 Cray supercomputers and IBM mainframes
Robust: Nothing is more powerful than allowing a programmer to recognize error conditions and
provide a software handler when such errors occur. Python provides "safe and sane" exits on errors,
allowing the programmer to be in the driver's seat. When Python exits due to fatal errors, a complete
stack trace is available, providing an indication of where and how the error occurred. Python errors
generate "exceptions," and the stack trace will indicate the name and type of exception that took place.
Python's robustness is beneficial for both the software designer as well as for the user.
Interpreted and (Byte-) Compiled: Python is classified as an interpreted language, meaning that
compile-time is no longer a factor during development. Traditionally purely interpreted languages are
almost always slower than compiled languages because execution does not take place in a system's native
binary language. However, like Java, Python is actually byte-compiled, resulting in an intermediate form
closer to machine language. This improves Python's performance, yet allows it to retain all the
advantages of interpreted languages.

Note1:
 Not compiled like many other languages (Java, C, C++)
 Code is written and then directly executed by an interpreter
 Type commands into interpreter and see immediate results.

Note2: compiled Interpreted

Explicitly Explicitly Implicitly Purely


Compiled Compiled Compiled to interpreted
to machine code to byte code byte code

C, C++, Fortran. Java, C# . Python. Shell, Perl.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 5 of 17


Compare python with other languages
Python has been compared with many languages. One reason is that it provides many features found in
other languages. Another reason is that Python itself is derived from many other languages, including
ABC, Modula-3, C, C++, Algol-68, Smalltalk, and Unix shell and other scripting languages, to name a
few.
Perl is another scripting language that goes well beyond the realm of the standard shell scripts. Like
Python, Perl gives you the power of a full programming language as well as system call access. Perl’s
greatest strength is in its string pattern matching ability, providing an extremely powerful regular
expression matching engine.
Python is often compared to Java because of their similar Object oriented nature and syntax. Python's
simplicity offers a much more rapid development environment than using just pure Java. One major
evolution in Python's relationship with Java is the development of Python, a Python interpreter written
completely in Java. It is now possible to run Python programs with only the presence of a Java VM
(virtual machine). You can manipulate Java objects, Java can interact with Python objects, and you have
access to your normal Java class libraries as if Java has always been part of the Python environment.
The classic “Hello, world!” program illustrates the relative verbosity of C, Java, and python.
C Program :
#include <stdio.h>
int main(int argc, char ** argv)
{
printf(“Hello, World!\n”);
}

java
public class Hello World
{
Public static void main (String[] args)
{
[Link]("Hello, world!"); //output : Hello, world!
}
}

Python
>>>print "Hello, world!"
>>>print("Hello, world!") # Python version 3 // output : Hello, world!

Matlab
Python consists of an extensive standard library as compared to Matlab, as shown in the following figure.

Department of Computer Science and Engineering Csen112 [Link].2025/2026 Page 6 of 17


Main Applications of Python:
Python is used across many application domains. Python enjoys a large user base and a very active
developer community. Because Python has been around for some 19 years and has been widely used, it is
also very stable and robust. Besides being employed by individual users, Python is also being applied in
real revenue-generating products by real companies. For instance:
 Google makes extensive use of Python in its web search systems, and employs Python’s creator.
 The You Tube video sharing service is largely written in Python.
 EVE Online, a Massively Multiplayer Online Game (MMOG), makes extensive use of Python.
 Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python for hardware testing.
 Industrial Light & Magic, Pixar, and others use Python in the production of animated movies.
 NASA, Los Alamos, Fermilab, JPL, and others use Python for scientific programming tasks.
 IRobot uses Python to develop commercial robotic devices.
 The NSA uses Python for cryptography and intelligence analysis.
 Python is used by Toyota company for developing AI applications.
 The One Laptop Per Child (OLPC) project builds its user interface and activity model in Python.

Major uses of python:


 System utilities (system admin tools, command line programs).
 Web Development.
 Graphical User Interfaces (Tkinter, gtk, Qt).
 Internet scripting.
 Embedded scripting.
 Database access and programming.
 Game programming.
 Rapid prototyping and development.
 Distributed programming

List of organizations using python: (sector-wise)


Web Development : Yahoo Maps, Yahoo Groups, Google, Zope Corporation, Ultraseek, Linux Weekly
News, ElasticHosts Cloud Servers, [Link], hunch, Shopzilla, [Link], [Link].
Games : Battlefield 2, Crystal Space, Star Trek Bridge Commander, The Temple of Elemental Evil,
Vampire: The Masquerade: Bloodlines, Civilization 4, QuArK (Quake Army Knife)
Graphics : Industrial Light & Magic, Walt Disney Feature Animation, HKS, Inc. (ABAQUS/CAE),
RoboFog, Caligari Corporation, Blender 3D, Jasc Software, Paint Shop Pro.
Financial : Altis Investment Management, ABN AMRO Bank, Treasury Systems, Bellco Credit Union,
Journyx Timesheet and Resource Management Software.
Science : National Weather Service, Radar Remote Sensing Group, Applied Maths, Biosoft, The
National Research Council of Canada, Los Alamos National Laboratory (LANL) Theoretical Physics
Division, AlphaGene, Inc., NASA, Swedish Meteorological and Hydrological Institute (SMHI),
Environmental Systems Research Institute (ESRI), Objexx Engineering, Nmag Computational
Micromagnetics.
Electronic Design Automation : Ciranova, Productivity Design Tools, Object Domain, Pardus, Red Hat,
SGI, Inc., MCI Worldcom, Nokia.
Education : University of California, Irvine, Smeal College of Business, The Pennsylvania State
University, New Zealand Digital Library, IT Certification Exam preparation, SchoolTool.
Business Software : Raven Bear Systems Corporation, Thawte Consulting, Advanced Management
Solutions Inc.,IBM, RealNetworks, dSPACE, Escom, The Tiny Company, Nexedi, Piensa Technologies.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 7 of 17


Flavors of Python :Now, let’s take a look at major Python implementations

CPython : This is the most widely accepted implementation of Python. It is written in the language C,
and is an interpreter.
Jython: Jython is a Python implementation written in Java. A Jython program can import any Java class.
It compiles to Java bytecode.
IronPython:IronPython is implemented in C#. It can function as an extensibility layer to application
frameworks written in a .NET language.
Brython:Brython stands for Browser Python. It is an implementation of Python that runs in the browser.
RubyPython: It acts as a bridge between the Python and Ruby interpreters. It marshals data between
Python and Ruby virtual machines.
PyPy: Interesting to know how PyPy is Python implemented in Python. This makes it faster and easier to
experiment with. However, the standard implementation is CPython.
MicroPython: This is an implementation of Python meant to run on a microcontroller. It uses a
MicroPython board that runs MicroPython on bare metal.
PythonFrameworks:

Django :Python Django is a free and open-source framework written in Python and is the most common
framework for Python. It allows you to create database-driven websites. It follows the DRY Principle
(Don’t Repeat Yourself). This is a design philosophy that keeps code simple and eloquent. Popular
websites like Instagram, Mozilla, and Disqus make use of it.
Flask:Like Django, Flask is a web framework written in Python itself. It is a micro framework because
it does not need certain libraries and tools. It also does not have form validation or a database abstraction
layer. However, you can make use of extensions to add extra features.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 8 of 17


Pyramid:Pyramid is another web framework. It is neither a mega-framework that would make decisions
for you nor a micro-framework that wouldn’t force [Link] gives you optimal liberty of your project.
Tornado:Another open-source web framework, Tornado is written in Python Language. It is noted for its
excellent performance and scalability.
Bottle:Like Flask, it is a micro-framework for Python. It is used for web development. Bottle is known
for its speed, simplicity, and lightweight. A single file can run both Python 2.5+ and 3.x.
web2py :Written in Python, web2py is another open source web framework. It emphasizes on rapid
development and follows an MVC architecture. MVC stands for Model View Controller.
NumPy:NumPy is an open-source framework for Python. We use it for scientific computing. It supports
large multidimensional arrays and matrices, and functions to operate on them.
SciPy:SciPy is a Python library that you can use for scientific computing. It has modules for linear
algebra, interpolation, fast Fourier transform(FFT), image processing, and many more. It uses
multidimensional arrays from the NumPy module.
Pylons:This is a deprecated framework, which means it is no longer recommended. It is a web
framework and is open source as well. It makes extensive use of third-party tools.
Downloading and Installing Python:
The most obvious place to get all Python-related software is at the main Web site at [Link] For
your convenience, you can also go to the book's Web site at [Link] and click on the
"Install Python" link to the left we have organized a grid with most contemporary versions of Python for
the most platforms, with a focus, of course, on the "Big Three." UNIX, Win 32, MacOS X.
Python is available on a wide variety of platforms. They can be broken down into these basic categories
and available platforms:
 All UNIX flavors (Linux, MacOS X, Solaris, FreeBSD, etc.)
 Win32 (Windows NT, 2000, XP, etc.)
 Older platforms: MacOS 8/9, Windows 3.x, DOS, OS/2, AIX
 Handhelds (PDAs/phones): Nokia Series 60/SymbianOS, Windows CE/Pocket PC
Starting Python :The first thing you need to do is install Python on the computer you are going to use.
It’s possible that Python is already installed on your computer, but for most people, that’s not the case.
So let’s look at how to install it
In Windows environment: Click Start, Point to programs folder, Python and then click IDLE command
from the submenu. As shown in the following figure

Python IDLE : Introduction


IDLE is an integrated development environment (an application like a word processor which helps
developers to write programs) for Python. IDLE is the Python IDE which comes with Python, built with
the Tkinter GUI toolkit.

It has two modes Interactive and Development.

Department of Computer Science and Engineering Csen112 [Link].2025/2026 Page 9 of 17


IDLE features
 Cross Platform : Works on Unix and Windows.
 Multi-window text editor with syntax highlighting and smart indent and other.
 Python shell window with syntax highlighting.
 Integrated debugger.
 Coded in Python, using the Tkinter GUI toolkit
Python IDLE: Interactive Mode
Let us assume that we've already installed Python (here we installed Python 3.2 on a standard pc with
windows 7 OS). Click on start button and find Python 3.2 tab in installed programs.

Now clicking on Python 3.2 tab you can see the Python program development tool named IDLE (Python
GUI).

To start IDLE click on IDLE (Python GUI) icon, you will see a new window opens up and the cursor is
waiting beside '>>>' sign which is called command prompt.

This mode is called interactive mode as you can interact with IDLE directly, you type something (single unit
in a programming language) and press enter key Python will execute it, but you can not execute your entire
program here. At the command prompt type copyright and press enter key Python executes the copyright
information.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 10 of 17


Now Python is ready to read new command. Let's execute the following commands one by one.
Command -1 : print("Hello World")
Command -2 : primt("Hello World")
The first command is correct and but the second one has a syntax error, here is the response from Python.

Python IDLE: Development mode, at first, start with a new window.

Clicking on "New window" under file menu a new window will come. Type print "Hello World" in the
new window.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 11 of 17


Let's save (Save command is located under the File menu) the file now. We save the program as
[Link] under E:/python-programs folder.

To run the program select Run menu.

Now click on Run Module or press F5 as a shortcut key to see the result.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 12 of 17


Python IDLE: Syntax Colors
Syntax Color
Keywords Orange
Strings Green
Comments Red
Definitions Blue

Python command line interface:


There are some users who prefer command line intersection, rather than a GUI interface. To go Python
command line, click on Python 3.2 tab then click on Python(command line).

Here is the screen shot of Python command line interface. To return type exit() or Ctrl+Z plus Enter key.

First program with python:


IDLE comes with a text editor The examples we’ve looked at so far are single Python instructions
(in interactive mode). While that’s great for checking out some of the things Python can do,
those examples are not really programs.
As I mentioned before, a program is a number of instructions collected together. So let’s make
our first Python program. First, you need a way to type in our program. If you just type it in
the interactive window, Python won’t “remember” it. You need to use a text editor (like Notepad
for Windows or Text Editor for Mac OS X) that can save the program to the hard drive.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 13 of 17


IDLE comes with a text editor that is much better for what you need than Notepad. To find it, select File
> New Window from IDLE’s menus. You will see a window like in the figure below. The title bar says
“Untitled” because you haven’t given it a name yet.

Now, type the program in listing below into the editor.


Print( "I love pizza! At Napoleon pizza house")
print ("pizza " * 20)
print ("yum " * 40)
print ("I'm full.)"
When you are done, save the program using the File > Save or File > Save As menu option.
Call the file [Link]. You can save it wherever you like (as long as you remember where it is, so
you can find it later). You might want to create a new folder for saving your Python programs. The
“.py” part at the end is important, because it tells your computer that this is a Python program,
and not just any old text file .
You might have noticed that the editor used some different colors in the program. Some words are
in orange and others are in green.
This is because the IDLE editor assumed that you would be typing in a Python program. For
Python programs, the IDLE editor shows Python keywords in orange and anything in quotation
marks in green. This is meant to help you read your Python code more easily.
Execution or Running your first program:
Once you have saved your program, go to the Run menu (still in the IDLE editor), and pick Run Module
(as shown in the next figure). This will run your program.

Python’s traditional runtime execution model: Source code ([Link]) you type is translated to byte
code , which is then run by the python virtual machine(PVM).

Your code is automatically compiled, but then it is interpreted. You will see that the Python shell window
(the one that first came up when you started IDLE) becomes active again, and you will see output in the
following window:

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 14 of 17


File Extensions in Python:
 .py –The normal extension for a Python source file
 .pyc- The compiled bytecode
 .pyd- A Windows DLL file
 .pyo- A file created with optimizations
 .pyw- A Python script for Windows
 .pyz- A Python script archive.
Types of Errors:
Programming is error prone. For whimsical reasons, programming errors are called bugs and the process
of tracking them down is called debugging.
There are three types of errors, such as: syntax error, runtime error and semantic error. It is useful to
distinguish between them in order to track them down more quickly.
1. Syntax Error (compile time error):
Syntax error refers to the structure of a program and the rules about that structure. For example
parenthesis have to come in matching pairs, so (1+2) is legal, but 8) is syntax error. If there is a single
syntax error in your program, python will display an error message and quit, and you will not be able to
run your program.
Example: i) >>>print (“Mainefhi”
ii) >>>a=” Mainefhi

2. Runtime Error (exception):


An error that causes abnormal termination of a program during running time is called runtime error.
Runtime error, so called because the error does not appear until the program has started running. These
errors are also called exceptions because they usually indicate that something exceptional or bad have
happened.
Example: i) >>>print(Mainefhi)
ii)>>>a=5
>>>b=0
>>>print(a/b)
3. Semantic Error (logical error):
If there is a semantic error in your program, it will run successfully in the sense that the computer will not
generate any error message, but it will not do the right thing. It will do something else. Specifically it will
do what you told it to do, but it is logically in correct. The problem is that the program you wrote is not
the program you wanted to write. The meaning of the program (or its semantics) is wrong.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 15 of 17


Identifying semantic error can be tricky because it requires you to work backward by looking at the
output of the program and trying to figure what is going on.

Example: suppose you want to add “a” and “b”, but instead if the program gives you an output the
product of the program, then you have to realize that there is a logical error in your program.

Summary:
A computer is a universal information-processing machine. It can carry out any process that can be
described in sufficient detail. A description of the sequence of steps for solving a particular problem is
called an algorithm.
Algorithms can be turned into software (programs) that determines what the hardware (physical machine)
can and does accomplish. The process of creating software is called programming.
Computer science is the study of what can be computed. Computer scientists use the techniques of
design, analysis, and experimentation. Computer science is the foundation of the broader field of
computing which includes areas such as networking, databases, and information management systems, to
name a few.
Programs are written using a formal notation known as a programming language. There are many
different languages, but all share the property of having a precise syntax (form) and semantics (meaning).
Computer hardware only understands a very low-level language known as machine language. Programs
are usually written using human-oriented high-level languages such as Python.
A high-level language must either be compiled or interpreted in order for the computer to understand it.
High-level languages are more portable than machine language. Python is an interpreted language. One
good way to learn about Python is to use the interactive interpreter for experimentation.
A Python program is a sequence of commands (called statements) for the Python interpreter to execute.
Python includes statements to do things such as print output to the screen, get input from the user,
calculate the value of a mathematical expression, and perform a sequence of statements multiple times.
Glossary:
Algorithm: A general process for solving a category of problems.
Bug: An error in a program.
Compile: To translate a program written in a high-level language into a low-level language all at once, in
preparation for later execution.
Debugging: The process of finding and removing any of the three kinds of programming errors.
High-level language: A programming language like Python that is designed to be easy for humans to
read and write.
Interactive mode: A way of using the Python interpreter by typing commands and expressions at the
prompt.
Object code: The output of the compiler after it translates the program.
Print statement: An instruction that causes the Python interpreter to display a value on the screen.
Program: A set of instructions in a particular order and language to solve a particular problem.
Prompt: Characters displayed by the interpreter to indicate that it is ready to take input from the user.
Script: A program stored in a file (usually one that will be interpreted).
Semantics: The meaning of a program.
Semantic error: An error in a program that makes it do something other than what the programmer
intended.
Source code: A program in a high-level language before being compiled.
Syntax: The structure of a program.

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 16 of 17


Exercises:
1. Differentiate between
a) Compiler and Interpreter
b) High level language and Low level language
c) Programmer and User
d) Application Software and System Software
e) Interactive mode and Script mode
2. Short answer questions /Conceptual questions
a) What is the advantage of python GUI over interactive mode?
b) What is the file extension for python compiled file?
c) What does a cross platform language mean?
d) What are the advantages and disadvantages of python programming language?
e) What are the advantages and disadvantages of interactive and script mode in python?
f) Python ‘Python is an interpreted high level language’. What does it mean to you?
g) Python programming language got its name from which show.
h) Who was python’s developer and which two languages contributed to python as a programming
language?
i) What are some limitations of python programming language?

3. Programming exercises: Check the out of the following on python 3.x version

a) print(“EIT”,+5)
b) print(“EIT”,*5)
c) print(“Asmara”,+6)
d) print(‘Hello world”)
e) print(“Hello”,” world”)

**************

Department of Computer Science and Engineering Csen112 [Link]. 2025/2026 Page 17 of 17

You might also like