EXAM
PACK
2025
, lOMoARcPSD|58918787
Visual Programming INF 1511
Unit 1- Python Environment & Data Operati ons
Describe the programming concepts for computi ng including performing arithmeti c
operati ons?
Outcomes:
1. Python and its features are explained.
2. Python is installed on different platforms.
3. Python is interacted with through Command Line Mode
4. A program is written in Python.
5. Comments, continuation lines and printing messages are written.
6. Arithmetic operations are performed.
Python:
Object orientated programming language
Implemented in C (Relies on portable C libraries)
Cross-platform language
Has a rich set of supporting libraries
Supports scripting - Suitable for rapid application development
Python Implementation:
Currently has 3 implementations:
o CPython
Most up to date and complete implementation.
Implemented in C.
Cross-platform.
o Jython
Java Virtual Machine (JVM) compliant.
Use all Java libraries and frameworks.
o IronPython
Implementation for Microsoft designed Common Language Runtime (CLR) known as .NET
Use all CLR libraries and frameworks.
Python Features:
Easy to learn.
Easier to read syntax.
o Avoids the use of punctuation characters like { } $ / and \.
Uses white space to indent lines.
Python is free.
o Developed under open-source model.
Large number of libraries included.
Can be integrated with other languages.
o C, C++ and Java.
Interpreted language.
o Supports a complete debugging and diagnostic environment.
Good choice for web development, networking, games, data processing and business applications.
Uses garbage collection for efficient memory management.
o Python run-time environment handles garbage collection.
o Reference counter ensures that no live objects are removed.
Python supports exception handling.
o Errors are raised as exceptions.
Interacting with Python:
Downloaded by Jonah Njenga ()
, lOMoARcPSD|58918787
Two ways to work with Python:
Command line mode.
IDLE IDE (Integrated development environment).
Command Line Mode
Type python instructions ONE LINE at a time.
OR import from other files or modules.
Accessed through the Python (Command Line) in the group.
o Alternatively - Open from the command prompt
Type python.
Press ENTER
ON OPENING of the Python (Command Line) menu item - Python command line window displays the Python
Prompt (>>>) where you can issue commands.
History of the commands given is maintained
IDLE (Integrated Development Environment)
Simple IDE.
Comes standard with Python distribution.
Combines an interactive interpreter with: #know this
o Code editing.
o Debugging tools.
o Several specialised browsers/viewers built into it.
Automatic indentation and colours to code based on Python syntax.
Complete Python keywords / user-defined values by pressing Alt + /
To Start IDLE:
IDLE (Python GUI) from group of applications.
Python shell will open.
Other methods to execute Python commands:
Write and edit Python programs in ANY editor, then execute through IDLE (Example - Notepad)
IDLE's built in editor
NOTE - Program will be saved as .py (extension shows that it is a Python program).
Writing Your First Program:
#This programme calculates the area of a rectangle.
#Input
l=8
b=5
a=l*b
#Processor
print("Area of rectangle",a)
#output
Area of Triangle 40
Notes:
#Program consists of two variables, l and b, initialized to
values 8 and 5
#Variables, l and b, represents the length and breadth of a
rectangle
#l and b are multiplied - Result stored in a
#to run the module - press f5
Downloaded by Jonah Njenga ()
, lOMoARcPSD|58918787
Data Types in Python:
Operations applicable on an object depend on its data type.
o INTEGERS
32 bits long
Range from -2³² to 2³²-1
Example: 10
o LONG INTEGERS
Unlimited precision.
Subject to the memory limitations of the computer
o FLOAT
Known as double precision values
64 bits long
Example : 10.0
o BOOLEAN
Can hold only one of two possible values
TRUE or FALSE
o COMPLEX NUMBER
3rd variable, a Real and imaginary component, both represented by float types
IMAGINARY NUMBER ( j ) - Multiple of the square route of minus one
Example:
√
2 + 3j -> 3 is the imaginary component equal to3 x −1.
o STRINGS
Sequence of UNICODE characters
Unicode - standard that uses 16-bit characters
Enclosed in " " or ' ' - quotes
Immutable
Example :
a='hello world'
o LISTS
Ordered sequence of values
Enclosed in [ ] – bracket.
Mutable
Example :
a=['Kate','Mary','John',10]
o TUPLES
Ordered, immutable sequence of values
Enclosed in ( ) - parenthesis
Example :
a=('Kate','Mary','John',10)
o SETS
Unordered collections of values
Enclosed in { } - curly brackets
Example :
s1={10,11,20,63,100}
o DICTIONARIES
Unordered collections of key/value pairs.
Enclosed in { } - curly brackets, key/value separation : - colon, item separation , - comma
Example :
s1={'John':80,'Kate':75}
Downloaded by Jonah Njenga ()