PPS Unit 1
PPS Unit 1
Total Marks:30
UNIT-1 19
Topics UNIT-2 16
Topics
2nd MILESTONE
2nd MILESTONE 6. Iterations
7. While loop
7. Introduction to python
8. For loop
8. Features of python
9. Python Loop control statements
9. Applications of python
10. Break statement
10. Writing First Python Code
11. Continue statement
12. Pass statement
13. else - Statement with Loop
3rd MILESTONE
11. Python fundamental 3rd MILESTONE
12. Reserved words
13. Identifiers 14. List
14. Variables 15. Tuple
15. Literal constants 16. Dictionary
16. Comments
17. Indentation
18. Operators
19. Data Types
UNIT-1 | 1st MILESTONE
1
U N I T
1
[email protected] WhatsApp 9673567922
UNIT-1 | 1st MILESTONE
[email protected]
2 WhatsApp 9673567922
UNIT-1 | 1st MILESTONE
(c). Find a place where limited number of people can be accommodated and go for day
trip.
(d). Go for a ride and order food at home.
(e). Decorate and order food at home and have home quarantine birthday celebration.
(iv) Select the best way
(a). Find a place where just your family can go for a day out and spend a day out so that
everyone is safe and can enjoy as well. It should be a property owned and secluded
from others.
(v) List out procedure
(a). Find places where you can visit which are safe and will give you a break in these
quarantine times.
(b). Check if that place is available.
(c). Use your vehicle for transport and carry all safety measures.
(d). Enjoy your day out with your family.
(e). Return back with beautiful memories of your birthday.
(vi). Evaluate the solution: birthday celebrated!!!
Types of Problem
Problem can be categorized into two types depending on how the solution is found out or the
approach which is followed to get that solution.
(i) Algorithmic solution
(a). These problems are solved by following some procedure or steps.
(b). For example: baking a cake. It can be done by following a series of instruction and
we can expect results.
(c). Here following some predefined process needs to be done.
(d). Here solution is quite straight forward.
(ii) Heuristic solution
(a). These types of problems solved using knowledge based i.e. by collecting information
about the problem.
(b). For example: Expanding one’s business.
(c). In this type of approach there is no straight forward defined path which we can fol-
low to solve a problem.
(d). We need to build that path based on trial and error.
(e). In this approach experience and knowledge is very important.
3
[email protected] WhatsApp 9673567922
UNIT-1 | 1st MILESTONE
[email protected]
4 WhatsApp 9673567922
UNIT-1 | 1st MILESTONE
5
[email protected] WhatsApp 9673567922
UNIT-1 | 1st MILESTONE
It represents conditional
4. Decision Box statements i.e. statements
with relational operators
[email protected]
6 WhatsApp 9673567922
UNIT-1 | 2nd MILESTONE
Start
accept i/p a1
b
c=a+b
Print c
Stop
Start
accept i/p r
area=3.14 *r*r
Print area
Stop
7
[email protected] WhatsApp 9673567922
UNIT-1 | 2nd MILESTONE
(1) Start
(2) Accept the input
(3) Compare the variables
if values of a and b are same then print
“They are equal”
if not same then print
“They are different”
(4) Stop
Pseudo Code
(1) Start
(2) Accept input a, b
(3) Compare variables
If a = = b, then print
“They are equal”
If a ! = b then print
“They are different”
(4) Stop
E xercise - 1.1
Question Based on 1st Milestone
Click or scan using
FORTFLAG app
for detailed
solution.
7. Introduction to Python
Python is one of the programming language like C, C++, Java etc.
It is interpreted, object oriented and high-level language.
Python was started in late 1980s by Guido Van Rossum at CWI in Netherland.
[email protected]
8 WhatsApp 9673567922
UNIT-1 | 2nd MILESTONE
In 1994, Python 1.0 was released with new features like: lambda, map, filter, and reduce.
Python 2.0 added new features like: list comprehensions, garbage collection system.
On December 3, 2008, Python 3.0 (also called “Py3K”) was released. It was designed to
rectify fundamental flaw of the language.
ABC programming language is said to be the predecessor of Python language which was
capable of Exception Handling and interfacing with Amoeba Operating System.
Software Data
Engineers Analysis Accountants + Kids
9
[email protected] WhatsApp 9673567922
UNIT-1 | 2nd MILESTONE
8. Features of Python
(i) Easy to Learn and Use
Python is easy to learn and use. It is developer-friendly and high level programming
language. As python community offer fast and effective support to the developers
and programmers, it brings down the development time and cost. With lots of module
available, web or application development become faster when user chooses Python.
(ii) Expressive Language
Python language is more expressive means that it is more understandable and readable.
(iii) Interpreted Language
Python is an interpreted language i.e. interpreter executes the code line by line at a time.
This makes debugging easy and thus suitable for beginners.
10 Reason to learn
Python
Easy to Learn and Use Object-Oriented Language
[email protected]
10 WhatsApp 9673567922
UNIT-1 | 2nd MILESTONE
9. Applications of Python
11
[email protected] WhatsApp 9673567922
UNIT-1 | 2nd MILESTONE
We will start with one of the simplest codes in Python syntax - the print Statement.
Whenever we learn a new language, it is an age-old tradition to start by displaying the
text “Hello World” on the screen.
Whatever we need to print is encapsulated in the parentheses following the print key-
word. Let’s try printing “Hello World” on the Practice terminal. The text Hello World is
bounded by quotation marks because it is a string or a group of characters. We will dis-
cuss about string in detail later.
INPUT CODE X
1 print(“Hello World”)
OUTPUT X
Hello World
[email protected]
12 WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
Next, we’ll print a few numbers. Each call to print moves the output to a new line:
INPUT CODE X
1 print (50)
2 print (1000)
3 print (3.142)
OUTPUT X
50
1000
3.142
We can even print multiple things in a single print command; we just have to separate them
using commas.
INPUT CODE X
OUTPUT X
E xercise - 1.2
Problem Based on 2nd milestone
Click or scan using
FORTFLAG app
for detailed
solution.
13
[email protected] WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
13. Identifiers
These are naming conventions used in python.
Identifier can be anything which is user defined.
Identifiers always starts with a character or underscore ( _ )
Python identifier is a name used to identify a variable, function, class, module or other
A
object.
n identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or
A
more letters, underscores and digits (0 to 9).
Use of blank space is not allowed in the identifiers instead we can use underscore.
Identifier may contain digits, strings. But after underscore or character.
Python does not allow punctuation characters such as @, $, and % within identifiers.
ython is a case sensitive programming language. This means, Variable and variable are
P
not the same.
Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
Starting an identifier with a single leading underscore indicates that the identifier is private.
tarting an identifier with two leading underscores indicates a strongly private identifier.
S
If the identifier also ends with two trailing underscores, the identifier is a language-
defined special name.
14. Variables
These are the entities whose value is not fixed.
Used for storing and manipulating data.
Variables are nothing but identifiers so the rules used for identifier are gain applicable
here.
In python variables need not to be declared and can be used directly.
Example: a = 10
name = “zeal”
Python variables can be reassigned, in that case previous content of variable will be
replaced replaced by new one.
[email protected]
14 WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
String variables can be combined together using (+) operator which is known as
concatenation. It is possible only when both the items are of same type.
Example: a = b = c = 10
Multiple values can be assigned to multiple variables in single declaration x, y, z = 4, 3.1
“Pune”.
Example:
1. >>> text1=’hello\
2. user’
3. >>> text1
4. hellouser’
5. >>>
15
[email protected] WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
Example:
1. >>> str2=’’’’’welcome
2. to
3. SSSIT’’’
4. >>> print str2
5. welcome
6. to
7. SSSIT
8. >>>
Numeric literals
Numeric Literals are immutable. Numeric literals can belong to following four different numeri-
cal types.
Int(signed integers)- Numbers( can be both positive and negative) with no fractional
part.
Example: 100
Long(long integers)- Integers of unlimited size followed by lowercase or uppercase L.
Example: 87032845L
Float(floating point)- Real numbers with both integer and fractional part eg: -26.2.
Complex(complex)-In the form of a+bj where a forms the real part and b forms the
imaginary part of complex number. eg: 3.14j
Boolean literals
A Boolean literal can have any of the two values: True or False.
Special literals
ython contains one special literal i.e., None.
P
None is used to specify to that field that is not created. It is also used for end of lists in
Python.
Example:
1. >>> val1=10
2. >>> val2=None
3. >>> val1
4. 10
5. >>> val2
6. >>> print val2
7. None
8. >>>
[email protected]
16 WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
Literal Collections Collections such as tuples, lists and Dictionary are used in Python.
List
List contains items of different data types. Lists are mutable i.e., modifiable.
The values stored in List are separated by commas(,) and enclosed within a square
brackets([]). We can store different type of data in a List.
Value stored in a List can be retrieved using the slice operator([] and [:]).
The plus sign (+) is the list concatenation and asterisk(*) is the repetition operator.
Example:
1. >>> list=[‘aman’,678,20.4,’saurav’]
2. >>> list1=[456,’rahul’]
3. >>> list
4. [‘aman’, 678, 20.4, ‘saurav’]
5. >>> list[1:3]
6. [678, 20.4]
7. >>> list+list1
8. [‘aman’, 678, 20.4, ‘saurav’, 456, ‘rahul’]
9. >>> list1*2
10. [456, ‘rahul’, 456, ‘rahul’]
11. >>>
16. Comments
These are non-executable statements written in a program.
They are for users or programmers understanding.
It gives information about that statement or a program.
Comments are optional and can be declared anywhere within a program.
In python the comments can be declared as
(i) Single line comment vIt is declared using hash (#) e.g. #This is a comment, too.
(ii) Multiline comments
(‘ ‘ ‘ ‘ ‘ ‘)
Example:
Programming in python is fun.
Sample program to show use of comments in python’’’
a=10 #10 is assigned to variable a
b=20
print(a+b) #print addition of a and b
17
[email protected] WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
17. Indentation
ost of the programming languages use curly braces ( { } ) to show the block of
M
statement.
But python uses indentations to show block of statements or sub-statements.
Indentation highlights block of statement.
All statement which are part of some other statement are written in a single column
with some space from the left.
Generally one tab or four spaces are included.
Example:
INPUT CODE X
OUTPUT X
INPUT CODE X
1 if a > b:
2 print(“a is greater than b”)
3 else:
4 print(“b is greater than a”)
OUTPUT X
18. Operators
Operators are used to process data.
Depending on the use the operators in python are as follows
[email protected]
18 WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
+ Addition
- subtraction
* Multiplication
/ Division
Calculate rest to power of variable
** Exponent i.e.xy x2
INPUT CODE X
OUTPUT X
19
[email protected] WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
Note:- When two operands are compared evaluated as either true of false. If True the
binary value is 1 , if false the binary value is 0.
True 1
False 0
Example:
== Equal to
!= Not equal to
INPUT CODE X
OUTPUT X
[email protected]
20 WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
Example:
If both sides of expression are true then
and Logical and
returns true
or Logical or If any of the side is true then returns true
not Logical not Gives negation of given output
INPUT CODE X
x = True
y = False
print (“x and y is”, x and y)
print (“x or y is”, x or y)
print (“not y is”, not y)
OUTPUT X
x and y is False
x or y is True
not y is True
21
[email protected] WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
INPUT CODE X
OUTPUT X
[email protected]
22 WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
Example:
• a=b
• a+=b a=a+b
• a–=b a=a–b
• a*=b a=a*b
• a/=b a=a/b
• a% = b a=a%b
INPUT CODE X
OUTPUT X
These operators are used to check presence of any value or data in given range.
(a) in – returns true if that item exists in a list or a range.
(b) not in – returns true if that item does not exists in given list or a range.
Example:
INPUT CODE X
23
[email protected] WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
OUTPUT X
True
False
True
True
False
Example:
INPUT CODE X
1 x1 = 5 #nonmutable
2 y1 = 5 #nonmutable
3 x2 = “hello” #nonmutable
4 y2 = “hello” #nonmutable
5 x3 = [1,2,3] #mutable
6 y3 = [1,2,3] #mutable
7 print(x1 is y1)
8 print(x2 is y2)
9 print(x3 is y3)
10 print(x1 is not y1)
11 print(x2 is not y2)
12 print(x3 is not y3)
OUTPUT X
True
True
False
False
False
True
Operator precedence
If an expression consisting of multiple operators then result of such expression is
calculated using operator precedence.
[email protected]
24 WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
Processing
Operator & Description
sequence
**
1 Exponentiation (raise to the power)
~+-
2 Complement, unary plus and minus
* / % //
3 Multiply, divide, modulo and floor division
+-
4 Addition and subtraction
>><<
5 Right and left bitwise shift
&
6 Bitwise ‘AND’
^|
7 Bitwise exclusive `OR’ and regular `OR’
<= <>>=
8 Comparison operators
<> == !=
9 Equality operators
= %= /= //= -= += *= **=
10 Assignment operators
is is not
11 Identity operators
in not in
12 Membership operators
not or and
13 Logical operators
enerally python do not require any variable to be declared as per the data assign to
G
variables interpreter automatically decides data type of variables.
25
[email protected] WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
(i) Numerical
umber stores numeric values. Python creates Number objects when a number is a
N
signed to a variable. For example;
a = 3 , b = 5 #a and b are number objects
Python supports 4 types of numeric data.
(a). int (signed integers like 10, 2, 29, etc.)
(b). long (long integers used for a higher range of values like 908090800L, -0x1929292L,
etc.)
(c). float (float is used to store floating point numbers like 1.9, 9.902, 15.2, etc.)
(d). complex (complex numbers like 2.14j, 2.0 + 2.3j, etc.)
ython allows us to use a lower-case L to be used with long integers. However, we must
P
always use an upper-case L to avoid confusion.
A complex number contains an ordered pair, i.e., x + iy where x and y denote the real and
imaginary parts respectively).
(ii) String
The string can be defined as the sequence of characters represented in the quotation
marks. In python, we can use single, double, or triple quotes to define a string.
String handling in python is a straightforward task since there are various inbuilt fun-
tions and operators provided.
Strings are declared using
‘ _ _ _ ’, “ _ _ ”, “ “ “___“ “ “
e.g.; a = ‘G’
print (a)
b = “Hello”
print (b)
C = “ “ “ Hello,
Everyone. How are
You today? “ “ “
print (C)
Strings can be combined together using (+) plus operator (concatenation)
e.g.; a = ‘Pune’
b = “Hello”
print (a + b)
Strings can be sliced by using slicing operation to slice given data following syntax is
used var_name [start : end]
[email protected]
26 WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
slicing start and end are optional if required they can be used or otherwise will carry
To
default values starting index as zero and end can be the complete length of data.
Example: a = ‘Pune is beautiful city’
print (a [ : ])
print (a [ : 4])
print (a [2 : ])
print (a [3 : 8])
(iii) List
It is an single variable which can store different types of elements.
It is similar to array accept that it can store different elements.
List are declared using [ ] (square brackets) and elements are separated using , (comma)
Example: a = [ ]
print (a)
data = [78, 4.5, ‘t’, ‘python’, 123456789]
print (data)
The plus and star operator is also used on list same as that of string.
Example: L1 = [1, 2, 3, 4]
L2 = [ 4, 5, 6]
print (L1 + L2)
print(L1 * 3)
Slicing is also executed / performed on list data type.
Example: L1 = [1, 2, 3, 4, 5, 6]
print (L1 [1 : 3])
List is mutable
Example: L1 = [1, 2, 3, 4, 5]
print (L1)
L1[2] = 100
print (L1)
Result: [1, 2, 3, 4, 5]
[1, 2, 100, 4, 5]
(iv) Tuple
Tuples are same as that of list accept tuples are non-mutable.
27
[email protected] WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
Example:
L1 (1, 2, 3, 4, 5)
print (L1)
L1 [2] = 100
print (L1)
Concatenation, repetition and slicing is also applicable in case of tuple data type.
(v) Dictionary
It is an ordered set of key and value.
It is like an hash table or associative array which stores keys with specific element.
Here key and value can be of any type i.e. integer, float, character or string.
Dictionary is defined using curly braces { } and pairs are separated by comma ( , ) key,
value pair is formed using colon ( : )
Example:
Example:
data = {1 : ‘one’, ‘two’ : 2, 4.5 : ‘decimal’, ‘name’ : ‘Pune’}
data [‘two’] = 8
print (data)
Concatenation, repetition and slicing are also applicable in case of dictionary data type.
[email protected]
28 WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
(a) Implicit
In this method data type is decided by interpreter depending on the value assigned.
Example: b = 10
In about e.g. given data is a rounded number i.e. 10 so interpreter will store it as a inte-
ger in the name of b.
(b) Explicit
In this method data is converted externally then assigned to the variable.
a = float (5)
In above e.g. data is converted externally i.e. 5 into float number then stored
into variable a.
E xercise - 1.3
Question Based on 3rd Milestone
Click or scan using
FORTFLAG app
for detailed
solution.
29
[email protected] WhatsApp 9673567922
UNIT-1 | 3rd MILESTONE
[email protected]
30 WhatsApp 9673567922