python unit 1 first half notes
python unit 1 first half notes
Chapter 1:
Introduction to Computing and Problem Solving:
1
OTHER COMPUTING DEVICES
A personal computer is designed to be a general-purpose device. That is, it can be used to solve
many different types of problems. Several types of devices that represent the latest trends in
personal computing.
PORTABLE COMPUTERS, SMART PHONES, TABLET COMPUTERS.
Computing technology is being integrated into many everyday products. From automobiles to
refrigerators to air planes, etc.
Here are two of the latest ways that computing technologies are being integrated into everyday
products:
The Smart House
The Self-Driving Car
Identification of Computational Problems
It is any type of calculation that includes both arithmetical and non-arithmetical steps and follows
a well-defined model
ALGORITHMS:
An algorithm is method of representing step by step procedure for solving a problem.
An algorithm is a part of the plan for the computer program. Infact, an algorithm is
‘an effective procedure for solving a problem in a finite number of steps’.
An algorithm is very useful for finding the right answer to a problem or breaking the difficult
problem into simple cases.
Problem
algorithm
Characteristics of Algorithm:-
An Algorithm must process the following characteristics
1. Finiteness
2. Definiteness
3. Effectiveness
4. Input
5. Output
2
1. Finiteness
An Algorithm should terminate in a finite number of steps
2. Definiteness
Each step of algorithm must be clear and unambiguous.
3. Effectiveness
Each step must be effective, in the sense that, it should be easily convertible into program
statement and can be performed exactly in a finite amount of time.
4. Input
Each algorithm must take Zero, one or more quantities as input data
5. Output
Each algorithm must produce atleast one output.
PseudoCode:-
The word pseudo means imitation and code means instructions written some programming language.
Pseudocode describes the structure of program in simple English language.
Pseudocode describes the complete logic of some programs that implementation become easy.
It does not use any syntax or symbols.
3
Flow chart Symbols
Terminator/Terminal:An oval flowchart shape indicates the start or end of the process, usually
Containing the word “Start ”or“ End
Connector:A small, labelled,circular flowchart shape used to indicate a jump in the process flow. Connectors are
generally used in complex or multi-sheet diagram.
4
Output data-processed result
State:
Transition from one process to another process under specified condition within a time
is called state.
Control flow:
The process of executing the individual statements in a given order is called controlflow.
The control can be executed in three ways
1. sequence
2. selection
3. iteration
Sequence:
All the instructions are executed one after another is called sequence execution.
Selection:
A selection statement causes the program control to be transferred to a
specific part of the program based upon the condition.
If the conditional test is true, one part of the program will be executed,
other wise it will execute the other part of the program.
Iteration:
In some programs, certain set of statements are executed again and again based
upon conditional test. i.e. executed more than one time.
This type of execution is called looping or iteration.
1.3.4 Functions:
5
Example1:To find sum of two numbers
Step1:Start/begin
Step2:DeclareNum1,Num2 andSum Step 3: Read Num1 , Num2
Step 4: Sum Num1+Num2 Step 5: Print or Display Sum
Step6:Stop/End
Step1:Start
Step 2: get l,b values
Step3:CalculateA=l*b
Step 4: Display A
Step5: Stop
Step1:Start
Step2:get r value
Step3:Calculate A= 3.14 * r * r
Step4:Calculate C=2.3.14 * r
6
Example4:Greatest of two numbers
Step1: Start
Step2: get a,b value
Step3: check if (a>b)
Print a is greater
Step 4: else b is greater
Step5: Stop
Example5:Write an algorithm & Flow chart to find the largest among three different
numbers entered by user.
Step1: Start Step2:
Get A,B,C
Step3: if (A>B) goto Step 4 else goto step5
Step4: If (A>C) print A else print C
Step5:If (B>C)print B else print C Step6:
Stop
.
PseudoCodeAlgorithm:-
Step 1: Start
Step2:get num
Step3:check if (num>0)
print “a is positive”
Step 4: else
print “num is negative” Step 5:
Stop
7
Example7:Write an algorithm and Draw a flow chart to login to your Gmail
Account
PseudoCode Algorithm:-
.
Step1:Start/begin
Step2:Goto www.gmail.com.
Step3:.Enter your email id and password
Step4:Click the Signin button
Step 5: Stop
Assignment:-
1. To check odd or even number
2. Write an algorithm to find sum of a given number
3. Write an algorithm to find factorial of a given number
4. Check given number is prime or not
5. GCD of two numbers
8
Chapter2:
Introduction to Python Programming:
Python Introduction
Python is the world's most popular and fastest-growing computer programming
language. It is a multi-purpose and high-level programming language.
Python was invented byGuido Van Rossum in the year 1989, but it was introduced into
the market on 20th February 1991.
Features of Python
The Python is a very popular programming language with the following features.
Python is easy to learn and easy to understand.
The Python is an interpreted programming language. It executes the code line by line.
9
The Python is a cross-plat form programming language. It can be used with any
operating system like Windows, Linux, MAC OS, etc.
The Python is a free and open-source programming language.
The Python isan Object-Oriented,Procedural and Functional programming language
The Python is a multi-purpose programming language
The Python is a high-level programming language
Python has a huge Community to get help all over the globe.
Python has a large Ecosystem of Libraries, Frame works, and Tools to work with it.
10
Python Interpreter
Python Interpreter is a program that reads and executes Python code. It uses 2 modes of
Execution.
1. Interactive mode
2. Script mode
Python Interactive Mode
In the interactive mode, We can query some statements, and python will
interpret/execute them and give you the output.
Interactive mode is useful to test out our code before keeping them to the scripts.
We can do operations likes calculations and printing some variables and etc.
To bring up the interactive python shell, Search for IDLE in windows.
We can write our statements into interactive shell, In above case wewritten
print("HelloPython")statement and pressed enter.
Then python immediately executed our print statement and displayed the output.
This is called interactive mode.
Where we can performs operations and get the results.
11
previous commands and if still, we could not edit we need to type everything again.
12
13