PSPP Theory Unit 2@
PSPP Theory Unit 2@
ALOK KUMAR
Assistant Professor/CSE
Government College of Engineering, Dharmapuri
OBJECTIVES
● To understand the basics of algorithmic problem solving.
● To learn to solve problems using Python conditionals and loops.
● To define Python functions and use function calls to solve problems.
● To use Python data structures - lists, tuples, dictionaries to represent
complex data.
● To do input/output with files in Python.
1. https://drive.google.com/file/d/1R3-xjos7u_MqPPY8Dy_oyIMz32nn9ExD/view?usp=sharing
2. https://drive.google.com/file/d/1pRs9tiNcxqqluZIk1FR-3OYAh1Biug51/view?usp=sharing
Features of Python:
1. Open Source
2. Easy to Learn
3. High Level Language
4. Portable
5. Object Oriented
(1) (2)
Government College of Engineering, Dharmapuri (ALOK KUMAR, A.P/CSE)
2. Development Mode
● for executing lengthy programs we can use this mode
● In this mode for making program firstly open New File and Type program in opened window
(1) (2)
Government College of Engineering, Dharmapuri (ALOK KUMAR, A.P/CSE)
● In this mode for saving program we have to click on Save As and we have to give any
file name (for example here hello) and extension as .py
(3) (4)
Government College of Engineering, Dharmapuri (ALOK KUMAR, A.P/CSE)
● In this mode for executing program we have to click on Run or F5 key and in new
window automatically output will come
(5) (6)
Government College of Engineering, Dharmapuri (ALOK KUMAR, A.P/CSE)
Debugging in Python:
● Debugging is the process of detecting and removing of existing and potential errors (also called as 'bugs')
in a program
● Debugging in Python is facilitated by pdb module (python debugger) which comes in-built to the Python
standard library.
● To start debugging within the program just insert import pdb, pdb.set_trace() command
Int:
● It contains positive or negative whole numbers (without fraction or decimal)
For example: a=5
Float:
● It is a real number with floating point representation. It is specified by a decimal point
For example: a = 5.0
Complex:
● It is specified as (real part) + (imaginary part)j
For example: 2+3j
4th
● Data type with one of the two built-in values, True or False
● It is denoted by the class bool
For example:
>>> 2+3
5
Here,
● + is the operator that performs addition
P – Parentheses
E – Exponentiation
M – Multiplication
D – Division
A – Addition
S – Subtraction
● The precedence of operators is listed from High to low
Output: -3
Government College of Engineering, Dharmapuri (ALOK KUMAR, A.P/CSE)
Illustrative Problems:
1) Exchange the value of two variables:
● In this program, we use the t variable to hold the value of variable a temporarily
● We then put the value of variable b in variable a and later variable t in variable b
● In this way, the values get exchanged
list=[10,20,30,40,50]
x=2 #Shift 2 location in positive direction (clockwise direction)
print(list[-x : ]+list[ : -x])
Output: [40,50,10,20,30]