0% found this document useful (0 votes)
13 views14 pages

Notes Intro To Python

Uploaded by

habibikuzaka
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)
13 views14 pages

Notes Intro To Python

Uploaded by

habibikuzaka
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

M.E.

S INDIAN SCHOOL, DOHA - QATAR


Notes-2 2025- 2026

Section : BOYS/GIRLS Date : 29-5-2025


Class & Div. : XI ALL DIVISIONS Subject: Computer Science
Lesson / Topic: Unit 2: Computational Thinking and Programming – I
• Introduction to Python
• Introduction to Problem solving
• Familiarization with the basics of Python programming:
• Data Handling in Python
• Control Structures in Python
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I. INTRODUCTION TO PYTHON PROGRAMMING
(a)INTRODUCTION:
It is widely used open source, Object Oriented, high level programming language, Developed by
Guido van Rossum in 1991.
He named it after getting inspired from watching the television show Monty Python's Flying Circus.
It is used for:
• software development,
• web development (server-side),
• system scripting
(b)FEATURES OF PYTHON
1. Easy to use – Due to simple syntax rule
2. Interpreted language – Code execution & interpretation line by line
3. Cross-platform language – It can run on Windows, Linux, and Macintosh etc. equally.
4. Expressive language – Less code to be written as it itself express the purpose of the code.
5. Completeness – Support wide rage of library
6. Free & Open Source – Can be downloaded freely and source code can be modify for improvement.
(c )SHORT COMINGS OF PYTHON
● Gets Slow in Speed: It is executing and finding the error line by line.
● Weak in Mobile Computing: Python is good in desktop and server platforms but weak in mobile
processor.
● Not easily convertible: Difficult to translate to other languages because of lack of syntax.
(d)HOW TO WORK WITH PYTHON
After installation of python, we can work on it in following ways.
(i) In Interactive mode (Python Shell)
(ii) In Script mode
Python shell is an interactive window where you can type in the python code and see the
output on the same window. It is an interface between the python command and the OS.

Type the commands after the command prompt, Python will immediately give you result.

(e)print STATMENT: print is a function in Python which helps you to display the specified content on

F 061, Rev 01, dtd 10th March 2020 1|Page


the screen. The content should be specified inside the parenthesis ( ).

(f)PYTHON SCRIPT MODE:


In this mode Python instructions are stored in files generated with .py extension and executed together
as one unit. Python instructions are known as Python Program. To open Script mode:

(g)EXITING FROM PYTHON

*************************************************************************************
II. INTRODUCTION TO PROBLEM SOLVING
(a)INTRODUCTION:
Problem-solving is a key skill in computer science where we create solutions to different challenges
through systematic steps.
(b)Steps for Problem Solving
[Link] the Problem
[Link] an Algorithm
[Link]
[Link]
[Link]
 (c)Algorithms: Algorithms are used to find the best possible way to solve a problem. An algorithm is a
set of instructions that is designed to accomplish a task. Algorithms can be represent in many ways
using Flowcharts, pseudocode..etc.

F 061, Rev 01, dtd 10th March 2020 2|Page


(d) Flowchart: A diagram that shows the flow of steps using symbols like ovals (start/end), rectangles
(processes), and diamonds (decisions).
 (e) FLOW CHART SYMBOLS

EXAMPLES:

F 061, Rev 01, dtd 10th March 2020 3|Page


Problem 4:Flow chart to check whether a given number is even or odd.

Problem 5:Flow chart for Finding the Simple Interest.

Formula:P*N*R/100

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

F 061, Rev 01, dtd 10th March 2020 4|Page


III. FAMILIARIZATION WITH PYTHON BASIC PROGRAMMING:

(a)PYTHON IS A CASE SENSITIVE LANGUAGE:

Here in first statement we use print () command, so the message or argument inside the (single ‘ ‘ OR double“ “
quotes) will display [Link] the second command we use Print() command, so Python will not be able to interpret it
and it shows error.
(b)PYTHON CHARACTER SET

(c) TOKENS
The smallest unit/element in the python program/script is known as a Token or a Lexical unit.
Python has following Tokens:
► Keywords
► Identifiers
► Literals
► Operators
► Punctuators
C.1 Keywords are the reserve words/pre-defined words/special words of python which have a special
meaning for the [Link]: if, else, break, continue, pass, True,False,None… etc
C.2 Identifiers are the name given to the different programming elements like variables, objects,
classes, functions, lists, dictionaries etc.

C.3 Literals are the data items that have a fixed or constant value.
A string literal is a sequence of characters surrounded by Quotes (Single, Double or
Triple Quotes).eg: Txt1 = “Hello World”
Numeric Literals are numeric values like integer floating point number or a complex
[Link]:pi=3.14,a=2+3j,a=2
A Boolean literal in Python is used to represen one of the two Boolean Values i.e. True
or [Link]: b=True
Special Literal – None(empty legal value), None literal is used to indicate absence of
[Link]: a= None
C.4 Operators: They are special symbols which represent [Link] are divided into two,Unary
Operator and Binary Operator.

Identity operator:is, is not.


Assignment Operator: =
Membership Operator: in , not in
Arithematic assignment operator OR short hand operators: +=,-=,*=,/=.//=.%=
C.4.1 Binary Operator:These operators is required two operands for its calculation.
Binary Operator :Arithematic Operators:It is used to perform mathematical operations such as
addition, subtraction, multiplication, division, and more.

F 061, Rev 01, dtd 10th March 2020 5|Page


F 061, Rev 01, dtd 10th March 2020 6|Page
C.5 Punctuators are the symbols that are used in programming language to organize sentence
structure, indicate the rhythm and emphasis of expressions, statements and Program Structure.
{ ],[],(), , , ” , ; , # , @ ,:

(d) COMMENTS IN PYTHON


These programs make them more readable and understandable. These are ignored by interpreter. Two
types of comments in Python
(a) Single line comments: can be created using hash( #) [Link]: # program to add two numbers.
(b) Multiline comments :are created using triple quotes (‘’’ ‘’’).eg: ‘’’Write a python program to find
the given number is even or odd, if odd find its square and if it is odd find its cube’’’

(e)
BARE BONES OF PYTHON

1. EXPRESSION: It is any legal combination of symbols that represents a value.


E.g. c=a+5, age=19, a>15
2. STATEMENT: It is a programming instruction that does something.
E.g. name=”Elsa”, print (“Name=”, name)
if age> 15:
welcome ()
3. COMMENTS: They are additional readable information to clarify the source code.
E.g. #This programs shows program components
#definition of the FUNCTION welcome () follows
4. FUNCTIONS: It is a code that has a name and it can be reused (execute again) by specifying its
name in the program.
E.g.: def welcome ():
print ("Welcome to Python World!")
5. BLOCKS AND INDENTATION: A group of statements which are a part of another statements or
a function are called block.

F 061, Rev 01, dtd 10th March 2020 7|Page


(f) VARIABLES
Variable is a name given to a memory location. A variable can consider as a container which holds
value. Python is a type infer language (Type inference refers to the automatic detection of the data
type of an expression) that means you don’t need to specify the datatype of [Link]
automatically get variable datatype depending upon the value assigned to the variable.
Practise OUTPUT
x=3
y=4
z=x+y
z=z+1
x=y
y=5
print(“x is =”,x)
print(“y is =”,y)
print(“z is =”,z)
PROGRAM NO 1
AIM:
WRITE A PYTHON PROGRAM TO PRINT THE NAME AND A WELCOME MESSGAE.
CODE:
name=input("Enter the name")
message=input("Enter the message")
print(name,message)
PROGRAM EXECUTED SUCCESSFULLY
OUTPUT:

F.1 Main components of a variable


In python every element is treated as an object.
Three main components of a variable /object is (A) identity (B) type (C) value
Identity: It refers to object’s address.
Type: Datatype of the object.
Value: Variables provides a means to name values, so that they can be used and manipulate
later.

Note: To bind value to a variable, will use assignment operator. (=)


E.g. x=8

F 061, Rev 01, dtd 10th March 2020 8|Page


PROGRAM NO 2
AIM:
WRITE A PYTHON PROGRAM TO ACCEPT 5 SUBJECTS MARKS AND FIND ITS SUM AND AVERAGE.
CODE:
phy=int(input(“Enter the Physics mark”))
che=int(input(“Enter the Chemistry mark”))
CS=int(input(“Enter the CS mark”))
mat=int(input(“Enter the Maths mark”))
eng=int(input(“Enter the English mark”))
sum=eng+phy+che+acc+CS
average=sum/5
print(“Total sum of score is:”,sum)
print(”The average is:”,average)
PROGRAM EXECUTED SUCCESSFULLY

OUTPUT

PROGRAM NO 3
AIM:
WRITE A PYTHON PROGRAM TO FIND THE SIMPLE INTEREST.
CODE:
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the interest rate: "))
time = float(input("Enter the time period in years: "))
# Calculate simple interest
interest = (principal * rate * time) / 100
print("Simple Interest:", interest)
PROGRAM EXECUTED SUCCESSFULLY
OUTPUT:
Enter the principal amount: 1000
Enter the Interest Rate: 5
Enter the time periods in year : 2
Simple Interest : 100.0

F.2 The standard variable assignment


L value and R value

F 061, Rev 01, dtd 10th March 2020 9|Page


F.3:TYPES OF VARIABLE ASSIGNMENT

Find the output


(1)

(2)
a = 10
a += 3
print(a)

OUTPUT
13
(3)
x=4
y = x > 2 and x < 10
print(y)

OUTPUT
True
(4)
x = True
y = False
print(x and y)

OUTPUT
False
(5)
a=1
b = “1”
print(a is b)

OUTPUT
False
(6)
text = "hello"
print("e" in text)

OUTPUT
True
F.4 DYNAMIC TYPING
F 061, Rev 01, dtd 10th March 2020 10 | P a g e
*********************************************************************************************
IV DATA HANDLING
[Link] TYPES:
Data Type specifies which type of value a variable can store. type () function is used to determine a
variable's type in Python.
[Link] IN CORE DATATYPES

2.1 NUMBERS DATA TYPE


Number data types are used to store numeric values in python. They are Integer (sub: Boolean), Floating
Point value and Complex Numbers.
• Integers or int are positive or negative numbers with no decimal point.
E.g: e.g. a=100 Output :-
b=-100 100 -100 200
c=1*20
print(a,b,c)
Type Conversion of Integer: int () function converts any data type to integer.
a = "101" # string Output :-
F 061, Rev 01, dtd 10th March 2020 11 | P a g e
b=int (a) # converts string data type to integer.
c=int (122.4) # converts float data type to integer. OUTPUT
print(b) 101
print(c) 122
• Boolean in Python It is used to store two possible values either True or False.
bool_1=(6>10) Output :-
print(bool_1) False
2.2 Floating point numbers It is a positive or negative real numbers with a decimal point.

eg:
a-101.2
b=-101.4
c=111.23
d=2.3*3
print(a)
print(b)
print(c)
print(d)

2.3 Complex numbers Complex numbers are combination of a real and imaginary part. Complex
numbers are in the form of X+Yj, where X is a real part and Y is imaginary part.
a = complex(5) # convert 5 to a real part val and zero imaginary part
print(a)
b=complex(101,23) #convert 101 with real part and 23 as imaginary part
print(b)
Output :-
(5+0j)
(101+23j)

[Link] DATA TYPE A sequence is an ordered collection of similar or different data types. Python
has the following built-in sequence data types:

String: A string value is a collection of one or more characters put in single, double or triple
quotes. E.g: “Hello” , ”a” , ‟‟‟this is a multiline comment‟‟‟‟ .
List : A list object is an ordered collection of one or more data items, not necessarily of the
same type, put in square brackets [ ].List can be modified or mutable.
E.g. A= [1, 2, 3, 4], b= [„a‟,‟e‟,‟i‟,‟o‟,‟u‟] , Student= [“Neha”, 25, 79.5,‟XI C‟]
Tuple: A Tuple object is an ordered collection of one or more data items, not necessarily of
the same type, put in parentheses ( ). ]. Tuples are immutable i.e. cannot be modified.
Eg: A= (10,20,30), B=(1,”Arjun”,:XI”,”C”)

F 061, Rev 01, dtd 10th March 2020 12 | P a g e


[Link] IN PYTHON
It is a combination of values i.e. constants, variables and operators. Operands contains the values an
operator uses. Operators are special symbols used for simple calculations.
E.g.: 2+2, 5+2*3 and 10/2-3
4.1 Converting Mathematical Expressions to Python Statements.
1) 3)(12) = 3*12
2) 4xy =4*x*y
3) ½ +3xy =(1/2)+3*x*y
4)A2+2AB+B2 =
(a*a)+(2*a*b)+(b*b) OR (a**2)+(2*a*b)+(b**2)

5) =G*((m1*m2)/r**2)

6) ab+ ab2 Do yourself


*************************************************************************************
VI CONTROL STRUCTURES IN PYTHON
Control statements are used to control the flow of execution depending upon the specified
condition/logic. There are three types of control statements.
1. Decision Making Statements
2. Iteration Statements (Loops)
3. Jump Statements (break, continue)

1.1Decision Making Statement OR Conditional statements


Decision making statement used to control the flow of execution of program depending upon condition.
There are three types of decision making statement.
1. if statements
2. if-else statements
3. Nested if-else statement
1.1.1 if statements
An if statement is a programming conditional statement that, if proved true,performs a function or
displays information.
Syntax: Eg: Program to check a number is positive or
if condition : negative
Statements num=int(input(“Enter the number”))
if num> 0:
print(“Number”,num ,”is positive”)
else:
print(“Number”,num ,”is negative”)

F 061, Rev 01, dtd 10th March 2020 13 | P a g e


Using logical operator in if statement
x=1
y=2
if (x==1 and y==2):
(“Condition matching the criteria”)

Output:-
Condition matching the criteria
1.1.2 if-else statements
If-else statement executes some code if the test expression is true (nonzero) and some other code if the
test expression is false.

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

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

F 061, Rev 01, dtd 10th March 2020 14 | P a g e

You might also like