0% found this document useful (0 votes)
5 views13 pages

python unit 1 first half notes

This document provides an introduction to computing, problem solving, and Python programming. It covers the fundamentals of computing devices, types of computers, algorithms, and the characteristics of algorithms, as well as the features and execution modes of Python. Additionally, it includes examples of algorithms and Python scripts to illustrate the concepts discussed.

Uploaded by

Menaka Patil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
5 views13 pages

python unit 1 first half notes

This document provides an introduction to computing, problem solving, and Python programming. It covers the fundamentals of computing devices, types of computers, algorithms, and the characteristics of algorithms, as well as the features and execution modes of Python. Additionally, it includes examples of algorithms and Python scripts to illustrate the concepts discussed.

Uploaded by

Menaka Patil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 13

Unit-I

Chapter 1:
Introduction to Computing and Problem Solving:

Fundamentals of Computing–Computing Devices


Computing devices are the electronic devices which take inputs, process the inputs and then
calculate results from the inputs. One of the most common computing device is computer which
we all know about it.
This is the vast field and it covers huge amount of devices today which we are using in one or
another form and these devices ranging from the simple Calculator, Printers, Digital Cameras,
Mobile phones, Smart phones , PC Desktops, Laptops and many more. These all do the math
calculations on the streams of binary digits(bitsi.e.0and1)and produce the results in different
forms that we need.
Processors
Every computing device will have the electronic calculator i.e. processor.This executes
calculations from the instructions given to them in the form of programming code.
Programming
Programming is the basic for executing computations. There can be two kinds of programming for
computers and that are Operating systems and Applications.
An Operating system(OS) helps the people to interact with the computing machine
Applications also known as apps,are examples of specialized programs that enable the computer
to carry out specific tasks.
Data Storage
Data storage is basically storing the programs as well as data on different memory devices used
in the computing devices today and these programs and data which are stored can be used later
for our needs. There are different storage devices using today.
Types of General-purpose Computers
There are basically two kinds of General-purpose computers and they are
1. Multi-user Computers
2. Dedicated Computers
Multi-user Computers
As the name suggests that this is a kind of computer that can handle multi users at a time. Main
frames, mini computers, and super computers all fall into this category.
Dedicated Computers
Dedicated computers are the computers which can be used by one user at a time. These
computers have replaced multi-user computers because they are simple and have less cost. PC
(Personal Computer is the most common dedicated computer these days
There are further two kinds of PCs which depends on their sizes and
portability. These PCs are Desktops and Laptops.

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

Input Computer Output

Steps for Algorithm Development:-


1. Initially understand the problem
2. Then, identify the expected output for the problem
3. Identify the necessary input for the problem.
4. Develop the logic that produces the expected output from the selected input.
5. Finally, test the algorithm with various set of inputs.

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.

Different ways of stating Algorithms

An algorithm can be written in following two ways:


1. Pseudocode
2. Flowchart

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.

Example:Adding two numbers


Step1:Start
Step2: Read input variable ‘A’.
Step3: Read input variable ‘B’.
Step4: compute the sum of A,B
Step5:Store the sum value in‘C’.
Step6: Print value ‘C’
Step7:End
FLOWCHARTS:-

A Flow chart is a type of diagram (graphical or symbolic)that represents an algorithm


or process.
Each step in the process is represented by a different symbol and contains a short
description of the process step.
The flowchart symbols are linked together with arrows showing the process flow direction.
A flowchart describes what operations (and in what sequence) are required to solve
agiven problem
Flowcharts are used in analyzing, designing, documenting or managing a processor
program in various fields

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

Process: A rectangular flowchart shape indicates a normal/generic process flow step.


For example,“Add 1 to X” or similar

Decision:A diamond flowchart symbol is used when a decision needs to be made,


commonly a Yes/No question or True/False test.

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.

Data: A parallelogram that indicates data input or output(I/O) for a process.


Examples: Get X from the user, Display X.

Arrow: used to show the flow of control in a process.

BUILDING BLOCKS OF ALGORITHMS (statements,state,controlflow,functions)


Algorithms can be constructed from basic building blocks namely, sequence, selection and
iteration.
Statements:
Statement is a single action in a computer. In a computer statements might include
some of the following actions
 Input data-information given to the program
 Process data-perform operation on a given input

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:

 Function is a subprogram which consists of block of code (set of instructions) that


performs a particular task.
 For complex problems , the problem is been divided into smaller and simpler tasks
during algorithm design.

5
Example1:To find sum of two numbers

Pseudo Code Algorithm:-

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

Example2:To find Area of Rectangle

Pseudo Code Algorithm:-

Step1:Start
Step 2: get l,b values
Step3:CalculateA=l*b
Step 4: Display A
Step5: Stop

Example3:Write an algorithm for Calculating area and circumference of circle


Pseudo Code Algorithm:-

Step1:Start
Step2:get r value
Step3:Calculate A= 3.14 * r * r
Step4:Calculate C=2.3.14 * r

Step 5: Display A,C


Step6:Stop

6
Example4:Greatest of two numbers

Pseudo Code Algorithm:-

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
.

Example6:To check positive or negative number

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.

 The Python programming language has been used by many people


likeSoftwareEngineers, Data Analysts, Network Engineers, Mathematicians, Accountants,
Scientists, and many more. Using Python, one can solve complex problems in less time
with fewer lines of code.

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.

Disadvantages of interactive mode


 The interactive mode is not suitable for large programs.
 The interactive mode doesn’t save the statements. Once we make a program it is for that
time itself, we cannot use it in the future. In order to use it in the future, we need to
retype all the statements.
 Editing the code written in interactive mode is a tedious task. We need to revisit all our

11
previous commands and if still, we could not edit we need to type everything again.

Python Script Mode


Script mode in Python is where we first write the Python program inside a script file and execute
it after that.
We can execute the script of code either using the Command prompt or using Python IDE
Installed in our system.

In order to run a code in script mode follow the following steps.


Step 1: Make a file using a text editor. You can use any text editor of your choice like
notepad.
Step2: After writing the code save the file using“.py extension.
Step 3: Now open the command prompt and command directory to the one where your
file is stored.
Step4: Type python “filename.py” and press enter.
Step5: You will see the output on your command prompt.
Example:
In order to execute "Hello Python" using script mode we first make a file and save it

Now we use the command prompt to execute this file.

12
13

You might also like