Unit 1 PDF
Unit 1 PDF
PROBLEM SOLVING 1
Computer
A computer is a machine that manipulates data according to a set of instructions.
A computer is a fast operating electronic device a that receives data (input ) and
process the data, stores data and produces the resultant data (output)
A computer is an electronic device used for storing data and to process to give the
desired results. They play and important role in our daily life. It reduces the manual
task, performs complex taxes easily in a fraction of seconds in nanoseconds speed.
Computers are used for variety of purposes, starting from simple arithmetic
calculations to very complex data analysis as weather forecasting, satellite
launching.
Classification of computers
• Computers are available in different shape, size and weights
• Due to these different shapes and sizes they perform different sorts of jobs from
one another.
• They can be classified in different ways.
Characteristics
• It operates by measuring.
• It functions on continuously varying quantity.
• The output is usually represented in the form of graphs.
• The calculations are first converted into equations and later converted into
electrical signals.
• The accuracy of the output is poor.
• It has limited memory space.
• It is not versatile, i.e. it has limited applications.
• Speed is very low.
Eg. Electronic weighing scale, patient’s heart beat, blood pressure, temperature.
b) Digital Computer
• As the name implies, the digital computer with quantities represented as digits.
• It is represented by binary notation in the form of 0’s and 1’s.
• Digital computers are much faster than analog computers and are more accurate.
• The basic operation performed by a digital computer is addition.
• Hence, the other operations such as multiplication, division, subtraction and
exponentiation are first changed into “Addition and then compute”.
• A digital signal consists of discrete voltage levels, a light pulses, that represent
either binary 1 (ON) or a binary 0 (OFF).
Characteristics
• It operates by counting.
• It functions on discrete numbers.
• The calculations are converted into binary numbers.
• Its accuracy is good.
• It has large memory space.
• It is versatile in nature.
• It is suitable for a number of applications.
• Its processing speed is high.
c) Hybrid Computer
Based on size and capacity, computers are classified into the following ;
(a)Microcomputer (b) Minicomputer (c) Mainframe computer (d)Super computer.
a) Micro Computer
• Because of its small size and use of Micro processer, this computer is called
Micro Computer.
• A micro processer is a processor whose components namely Input, Output and
CPU are on a single integrated- circuit chip.
• It is a low –cost
• the word length of a micro computer lies in the range of 8to 32 bits.
• These mainly used in offices, homes, schools, shops, stores etc.
• IBM PCs, Apple Mac, IBM PS/2 are some popular computers of this range.
Advantages:
• They are small and portable.
• They are relatively inexpensive.
• They work as soon as they are switched on.
• They do not occupy much space.
• They do not consume much power.
Disadvantage:
b) Mini Computer
• Mini computers are larger than the micro computers and are more powerful in
terms of processing power.
• Mini computers are mainly multi processor systems where many users
simultaneously work on the systems.
• These are even capable of handling more input-output device.
• Their word length is 32 bits.
• The processing speed lies in the range 10 to 30 MIPS, memory (RAM) capacity
lies in the range 8MB to 256MB.
• The hard disk capacity lies in the range 380to 3G,it can support up to 64 or even
hundred terminals
• It is used for payroll preparation, accounting and scientific computation.
• High performance workstations with graphics input/output capability use
minicomputer.
Advantages:
• It is a general purpose computer.
• Its storage capacity is about 2Mega words.
• It can support all high level language.
• It can support many terminals i.e. more than 20 terminals.
• It performs almost all the task that a mainframe computer do.
• It is relatively inexpensive.
Disadvantage:
• They are slower when compared with main frame computers.
• The memory of mini computers are smaller than mainframes.
c) Mainframe computer
• Mainframe computer are larger ,
• Faster and more expensive than other general purpose computers .
• These are used to handle huge volumes of data.
• Their word length may be 48 to 64 bit memory capacity
• the hard disk capacity 100MB to 10 GB or more and processing speed 30 to
100MIPS.
• These computer work with more than one processor at the same time.
• Thus one can see these as multi-user, multiprocessor systems.
• They are used where large amount of data are to be processed or very complex
calculations are to be made
• It used in research organizations, large industries, large business and
government organizations, banks and airline reservation where large database is
required.
Advantages:
• They are capable of handling all tasks.
• They require large room space.
• Consumption of electricity is very high.
• Maintenance cost is also very high.
d) Super computer:
• Super computer is the most powerful of all computers.
• They have a high processing speed.
• Their processing speed lies in the range of 400 to 10,000 MIPS,
• The word length 64 to 96 bit or more.
• Memory capacity 256 MB or more,
• Hard disk designed to maximize the number of FLOPS.
• Their FLOPS rating is usually more than 1 gigaflops per second.
• Supercomputers are mainly used for purposes requiring enormous amounts of
data to be processed within a very short time,
• Whether Forecasting, Space Research, Weapon Research, Atomic Research,
Design of Aircrafts etc., are some of the applications.
• The best known super computers are PARAM series (developed in India)
• Super computer can perform billions of instructions per second.
Advantages :
• They use several processors working simultaneously.
• The process at a rapid speed.
• They have more main memory.
• They have operations done in parallel, rather than sequentially.
a) Palmtop computer
• The palmtop computers accept handwritten inputs using an electronic pen,
which can be used to write on a Palmtop’s screen (besides a tiny keyboard).
• These have small disk storage and can be connected to a wireless network.
• One has to train the system on the user’s handwriting before it can be used as a
mobile phone, Fax and E-mail machine.
• A version of Microsoft Operating System called Windows-CE is available for
palmtops.
b) Laptop Computer
• Laptop PC’s are portable computers with less weight and small enough to rest it
on the lap.
• They use a keyboard, flat screen liquid crystal display, and a Pentium processor.
• Laptop computer generally smaller than a briefcase that can easily be
transported.
• Laptops come with hard disk, CD ROM and floppy disk drives.
• It will run in batteries. Many Laptops can be connected to a network.
• As Laptops use miniature components which consume low power and have to
be packaged in small volume.
c) Personal computers
• The personal computers were mainly designed to meet the personal computing
requirements of users at working place or at home.
• It is a non-portable and general purpose computer which can easily fit in on a
normal size office table.
• The personal computers are also almost used by the children and adults for
education and entertainments and hence they are now common everywhere.
• The personal computers configuration varies from one another based on their
use. It consists a CPU, monitor, a keyboard and a mouse.
• It is usually designed the following two models.
• Desktop model
• Tower model
d) Work Stations
• It is a powerful desktop computer designed to meet the computing needs of
users or clients, with better processing, high storage capacity and with efficient
and effective graphics display facility.
• The workstation looks similar to a personal computer and can be used by only
one person at a time through the Local Area Network.
e) Mainframe system
• The mainframe system is commonly used for handling voluminous data and in
an environment where a large number of users need to share a common
computing facility.
• It is housed in a central location with several user terminals and peripherals
connected to it. The user terminals are connected with the host processor for
accessing as and when required.
f) Clients and Servers
• With the increased gain of computer networks, it is possible to interconnect
several computer for communicating over the networks to share the several
resources or services among the multiplier user.
• i)Server: It is a large computer that manages a shared resources and provides a
set of shared user services to the client.
ii)Client: It is a single user personal computer or workstation and supports a
user friendly interface with the end user. It sends request to the server and then gain
access with the server.
Generation of Computer:
Algorithm
An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving
a problem, based on conducting a sequence of specified actions.
Logical thinking scientifically exposes something in an abstract. Once the logic of
the problem is identified, the next step is to form the correct sequence and procedure
of instructions to carry out the task.
• Algorithm is correct a sequence of procedural instruction required to carry out the
task.
• The Algorithm is often used to refer the logic of a program.
• It is one of the basic tool used to develop the problem solving
• A computer program can be viewed as an elaborate algorithm.
• To multiply single-digit numbers, you probably memorized the multiplication
table. In effect, you memorized 100 specific solutions. That kind of knowledge is
not algorithmic.
• But if you were “lazy”, you might have learned a few tricks. For example, to
find the product of n and 9, you can write n * 1 as the first digit and 10 * n as the
second digit. This trick is a general solution for multiplying any single-digit
number by 9. That’s an algorithm!
• Similarly, the techniques you learned for addition with carrying, subtraction
with borrowing, and long division are all algorithms.
• One of the characteristics of algorithms is that they do not require any
intelligence to carry out the task. They are mechanical processes where each step
follows from the last according to a simple set of rules.
• Some of the things that people do naturally, without difficulty or conscious
thought, are the hardest to express algorithmically. Understanding natural
language is a good example.
Characteristics of Algorithm
• In Algorithms each and every instruction should be precise and clear-cut.
• The instruction in an algorithm should not be repeated infinitely.
• The algorithm makes sure that it will ultimately be terminated.
• Algorithm should be written in sequence.
• It looks like normal English.
• The desired result should be obtained only after the algorithm terminated.
Quality of a good Algorithm
• There are many methods or logic available for problem solving. All of those
method and logic may not be good, for given problem.
• The following are the primary factors that are often used to judge the quality of
the algorithm.
Representation of Algorithm
• The algorithm can be represented in several ways. Generally the programmer
follows one of the following ways.
Normal The Algorithm can be easily represented in step by step sequence
English order in normal English, such algorithm are easy to understand write
and read.
Flow Chart The flowchart is a pictorial representation of an algorithm. i.e.
algorithm can be represented as a flow chart using standard symbols.
Pseudo Pseudo code is also a formal design tool and utilized very well with
code the rules of structured design and programming.
A decision table helps a lot in designing a specific segment of a
Decision
design. It provides another way to look at a complex, nested selection
table
to help clarify the conditions to be tested and how those conditions
should be nested to arrive at the proper actions.
Program The algorithm represented as a program using any high level
language that becomes a program.
Algorithm to get a valid email from the user:
Analysis of Algorithms
• The practical goal of algorithm analysis is to predict the performance of
different algorithms in order to guide design decisions.
• The goal of algorithm analysis is to make meaningful comparisons between
algorithms,
and bring out the best one.
Order of growth
• For algorithmic analysis, functions with the same leading term are
considered equivalent, even if they have different coefficients.
• An order of growth is a set of functions whose growth behavior is considered
equivalent.
• For example, 2n, 100n and n+1 belong to the same order of growth, which is
written O(n) in Big-Oh notation and often called linear because every function in
the set grows linearly with n.
• All functions with the leading term n2 belong to O(n2); they are called quadratic.
• The following table tells about the various order of growth in the algorithms and
their names.
Sequential Control
• The algorithm and its steps are to be carried out in a sequential manner.
• Each step is executed exactly once.
• It does not have a branch or control flow.
• The final steps displays the desired output.
Selection or Conditional Control
• The algorithm and its steps are carried out on selection basics.
• The selection is done based on the condition.
• One of the number of alternative steps are executes based on a condition.
Reserved Words
• Keywords are the reserved words in Python.
• We cannot use a keyword as variable name, function name or any other identifier.
• They are used to define the syntax and structure of the Python language.
• In Python, keywords are case sensitive.
• There are 33 keywords in Python 3.3. This number can vary slightly in course of
time.
• All the keywords except True, False and None are in lowercase and they must be
written as it is.
• The lists of all the keywords are given below.
as elif if or yield
assert else import pass
break except in raise
Identifiers
• Identifier is the name given to entities like class, functions, variables etc., in
Python.
• It helps differentiating one entity from another.
• Identifiers are the names given to the fundamental building blocks in a program.
• Some identifiers are built-in, and others can be created by the programmer.
• User-defined identifiers can consist of letters, digits, underscores, and the dollar-
sign $.
Types of Strings:
There are two types of Strings supported in Python:
• Single line String- Strings that are terminated within a single line are known as
Single line Strings.
• Multi line String- A piece of text that is spread along multiple lines is known as
Multiple line String.There are two ways to create Multiline Strings:
Numeric literals:
Numeric Literals are immutable. Numeric literals can belong to following
four different numerical types.
Int(signed float(floating
Long(long Complex(complex)
integers) point)
integers)
In the form of a+bj
Numbers (can be Integers of
Real numbers where a forms the
both positive and unlimited size
with both integer real part and b forms
negative) with followed by
and fractional the imaginary part of
no fractional lowercase or
part Example: - complex number.
part. uppercase L
26.2 Example: 3.14j
Example: 100 Example:
87032845L
Boolean literals:
• A Boolean literal can have any of the two values: True or False
Special literals:
• Python contains one special literal i.e., none.
• None is used to specify to that field that is not created.
• It is also used for end of lists in Python.
Literal Collections:
• Collections such as tuples, lists and Dictionary are used in Python.
• We will see them in the following chapters.
List:
• List contains items of different data types.
• Lists are mutable i.e., modifiable.
• The values stored in List are separated by commas(,)
• Each value is 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
• Asterisk(*) is the repetition operator.
Operators
• Operators are particular symbols which operate on some values and produce an
output.
• The values are known as Operands.
Python supports the following operators:
• Arithmetic Operators.
• Relational Operators.
• Assignment Operators.
• Logical Operators.
• Membership Operators.
• Identity Operators.
• Bitwise Operators.
Arithmetic Operators:
Operators Description
// Perform Floor division(gives integer value after division)
+ To perform addition
- To perform subtraction
* To perform multiplication
/ To perform division
% To return remainder after division(Modulus)
** Perform exponent(raise to power)
Relational Operators:
Operators Description
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to
<> Not equal to(similar to !=)
Assignment Operators:
Operators Description
= Assignment
/= Divide and Assign
+= Add and assign
-= Subtract and Assign
*= Multiply and assign
%= Modulus and assign
**= Exponent and assign
//= Floor division and assign
Logical Operators:
Operators Description
and Logical AND(When both conditions are true output will be
true)
or Logical OR (If any one condition is true output will be true)
not Logical NOT(Compliment the condition i.e., reverse)
Membership Operators:
Operators Description
in Returns true if a variable is in sequence of another
variable, else false.
not in Returns true if a variable is not in sequence of another
variable, else false.
Identity Operators:
Operators Description
is Returns true if identity of two operands are same, else
false
is not Returns true if identity of two operands are not same, else
false.
State
• An algorithm describes a computation.
• When executed, proceeds through a finite number of well-defined successive
states.
• States are the temporary intermediate stages in the flow of execution.
• Partial output like intermediate output obtained called states.
• These outputs are then eventually produces the output terminating at a
final ending state.
• The transition from one state to the next is not necessarily deterministic.
Figure:stated
iagram
• State diagram: A graphical representation of a set of variables and the values
they refer to.
Reassignment
• It is legal to make more than one assignment to the same variable.
• A new assignment makes an existing variable refer to a new value (and stop
referring to the old value).
• This is called as reassignment.
• The first time we display x, its value is 5; the second time, its value is 7.
• The third line changes the value of ‘a’, but does not change the value of b.
• So they are no longer equal.
• Reassigning variables is often useful, but you should use it with caution.
• If the values of variables change frequently, it can make the code difficult to
read and debug.
Updating variables
• A common kind of reassignment is an update, where the new value of the
variable depends on the old.
• This means “get the current value of x, add one, and then update x with the new
value”.
• If you try to update a variable that doesn’t exist, you get an error, because Python
evaluates the right side before it assigns a value to x.
• Before you can update a variable, you have to initialize it, usually with
a simple assignment.
• Updating a variable by adding 1 is called an increment; subtracting 1 is called a
decrement.
Control Flow
• (if/elif/else)
• Controls the order in which the code is executed.
• Blocks are delimited by indentation.
• The I python shell automatically increases the indentation depth after a column(:)
sign; to decrease the indentation depth, go four spaces to the left with the
Backspace key.
• Press the Enter key twice to leave the logical block.
• Indentation is compulsory in scripts as well.
for/range
• Iterating with an index.
But most often, it is more readable to iterate over values:
while/break/continue
• Typical C-style while loop (Mandelbrot problem):
More advanced features
• break out of enclosing for/while loop:
• continue the next iteration of a loop.:
Conditional Expressions
• if object
• Evaluates to True:
• any non-zero value
• any sequence with a length > 0
• Evaluates to False:
• any zero value
• any empty sequence
• a == b, Tests equality, with logics:
• a is b, Tests identity: both objects are the same.
• a in b, For any collection b: b contains a
• If b is a dictionary, this tests that a is a key of b.
Call a function
Calling a function in Python is similar to other programming languages, using the
function name, parenthesis (opening and closing) and parameter(s). See the syntax,
followed by an example.
Syntax
function_name(arg1, arg2)
Example :
def function_name() :
statement_1
statement_2
....
Example :
def printt():
print("This is Python 3.2 Tutorial")
print("This is Python 3.2 Tutorial")
print("This is Python 3.2 Tutorial")
printt()
Output :
The following function returns the square of the sum of two numbers.
def nsquare(x, y):
return (x*x + 2*x*y + y*y)
print("The square of the sum of 2 and 3 is : ", nsquare(2, 3))
Output :
Default Values:
In function's parameters list we can specify a default value(s) for one or more
arguments. A default value can be written in the format "argument1 = value", therefore
we will have the option to declare or not declare a value for those arguments. See the
following example.
Example :
The following function returns the square of the sum of two numbers, where default
value of the second argument is 2.
Output :
Keyword Arguments
We have already learned how to use default arguments values, functions can also be
called using keyword arguments. Arguments which are preceded with a variable name
followed by a '=' sign (e.g. var_name=") are called keyword arguments.
All the keyword arguments passed must match one of the arguments accepted by the
function. You may change the order of appearance of the keyword. See the following
example.
Example :
Explanation :
Line 1 : The function named marks has three parameters, there is no default value in the
first parameter (english) but remaining parameters have default values (math = 85,
science = 80).
Line 3 : The parameter english gets the value of 71, math gets the value 77 and science
gets the default value of 80.
Line 4 : The parameter english gets the value of 65, math gets the default value of 85
and science gets the value of 74 due to keyword arguments.
Line 5 : Here we use three keyword arguments and the parameter english gets the value
75, math gets the value 90 and science gets the value 70.
Example :
def sum(*numbers):
s = 0
for n in numbers:
s += n
return s
print(sum(1,2,3,4))
Output :
10
Lambda Forms
In Python, small anonymous (unnamed) functions can be created with lambda
keyword. Lambda forms can be used as an argument to other function where function
objects are required but syntactically they are restricted to a single expression. A
function like this:
3.5
Methods
• Methods are simply another kind of function that resides in classes.
• You create and work with methods in Python in precisely the same way
that you do functions, except that methods are always associated with a
class.
• You can create two kinds of methods:
• Those associated with the class itself .
• Those associated with an instance of a class.
• The example outputs the expected string. Notice that you didn’t need to
create an instance of the class — the method is available immediately for use.
Type the following code (pressing Enter after each line and pressing Enter twice
after the last line):
• The example class contains a single defined attribute, SayHello().
• This method doesn’t accept any special arguments and doesn’t return any values.
• It simply prints a message as output. However, the method works
just fine for demonstration purposes.
Type MyInstance = MyClass() and press Enter.
• Python creates an instance of MyClass named MyInstance.
You see this message. After this step close the window.
Notations
Pseudo code
• Pseudo code is an ordered version of your code written for human
understanding rather than machine understanding.
• Pseudo code is a formal design tool, developed with the structured programming.
• It is a programming analysis tool that is commonly used for planning the program
logic.
• The name itself specifies “Pseudo” means imitation, “Code” means the set of
statements or instructions written in a programming language.
• Pseudo code is also called “Program Design Language (PDL)”.
• The pseudo code is written in normal English and cannot be understood
by the computer.
• During the design of pseudo code, the designer or programmer can only
concentrate the logic of the program without worrying the syntax of the
instructions.
• There is no one set way to write pseudo code.
Advantages:
• It can be done easily in any word processor.
• It can be easily modified as compared to flowchart.
• It’s implementation is very useful in structured design elements.
• It can be written easily.
• It can be read and understood easily.
• Converting a pseudo code to programming language is very easy to
compare with converting a flowchart to programming language.
Disadvantages:
• It is not visual.
• We do not get a picture of the design.
• There is no standardized style or format, so one pseudo code may be
different from another.
• For a beginner, it is more difficult to follow the logic or write pseudo code as
compared to flowchart.
Characteristics of a good pseudo code should:
• not be in a specific coding language
• draft the structure of your code
• be understandable to humans
Flowchart
The flowchart is a diagrammatic representation that illustrates the sequence of
operation to be performed to arrive at the solution. The operating instructions are
pleased in symbols which are connected by arrows to indicate the order of execution
• Only one flow line should enter a decision symbol but two or three flow line
one for each possible answer, should leave the decision symbol.
• Only one flow line is used in conjunction with terminal symbol.
• Flow line should not cross each other.
• Be consistent in using name and variable in the flowchart.
• Words in the flowchart symbol should be common statement and easy to
understand.
• Keep flow chart as simple as possible.
Basic Design Structure in Flowchart
• Sequence Structure
• Selection Structure
• Loop Structure
• Top Tested Loop
• Bottom Tested Loop
Tips to draw complex Flowcharts
• For loops normally repeat a nested block of code a set number of times or for a
set range of data.
• while loops repeat a set block of code while a condition is true.
• The diamond symbol is used with loops to show the way the computer repeats a
nested block of code then moves on to the next step.
• One of the easiest ways to think about it is that there are normally two
paths the computer can go down when it reaches a loop:
• the code in the loop
• the code after the loop
For example:
Note: In this example there is no code after the loop so we represent this with the end
symbol.
Functions in flowcharts
• Another type of symbol that is important for more advanced programs is the
symbol used for functions.
• Functions are sometimes also known as modules or pre-defined processes; they
represent a completed block of code that can be called form other parts of a
program.
Representing the contents of functions in flowcharts.
• A common way to represent the contents of functions is with separate
unconnected flowcharts.
• The name of the function is normally added to the start symbol in these
unconnected
flowcharts.
• There may be times when you do not need to show the contents of every function
in your flowchart.
• The example below shows a rough diagram of a program that makes use of
functions that convert Farenheit to Celcius and compare the current temperate
to the monthly
average.
• This is a rough example only to show the idea of how you can represent functions
in flowcharts; often the functions will be far more complex than the examples
below.
Sample Flowcharts, Pseudo code and Python Code
Example 1:
This program asks the user their name then says "Hello [Name]":
Note: This flow chart only shows ovals and parallelograms because the code only has
start and end and one input and one output.
Example 3
• This program asks the user how many hours a week they work and how much
they earn per hour as two separate inputs. It then calculates how much money
they earn a week and outputs two different sentences based on how much they
earn.
What is python ?
• Python is an object-oriented, high level language.
• It is interpreted, dynamic and multipurpose programming language.
• Python is easy to learn yet powerful and versatile scripting language which makes
it attractive for Application Development.
• Python's syntax and dynamic typing with its interpreted nature, make it an ideal
language for scripting and rapid application development in many areas.
• Python supports multiple programming pattern, including object oriented
programming, imperative and functional programming or procedural styles.
• Python is not intended to work on special area such as web programming. That is
why it is known as multipurpose because it can be used with web, enterprise, 3D
CAD etc.
• In python we don't need to use data types to declare variable because it is
dynamically typed so we can write a=10 to declare an integer value in a variable.
• Python makes the development and debugging fast because there is no
compilation step included in python development.
• edit-test-debug cycle is very fast in python.
Python Features:
• There are a lot of features provided by python programming language.
Features Explanation
Easy to Use: Python is easy to very easy to use and high level
language. Thus it is programmer-friendly language.
Expressive Language: Python language is more expressive. The sense of
expressive is the code is easily understandable.
3) Interpreted Python is an interpreted language i.e. interpreter executes
Language: the code line by line at a time. This makes debugging easy
and thus suitable for beginners.
Python History:
• Python laid its foundation in the late 1980s.
• The implementation of Python was started in the December 1989 by
Guido Van Rossum at CWI in Netherland.
• ABC programming language is said to be the predecessor of Python language which
was
capable of Exception Handling and interfacing with Amoeba Operating
System.
• Python is influenced by programming languages like ABC language, Modula-3.
Python Version:
Python programming language is being updated regularly with new features and
support. There are a lot of updation in python versions, started from 1994 to
current date. A list of python versions with its released date is given below.
Python Applications
• Python as a whole can be used in any sphere of development.
• There are several such applications which can be developed using Python.
• Let us see what are the major regions where Python proves to be handy.
Application: Features
Console Based Application Python can be used to develop console
based applications. For example: IPython.
Audio or Video Python proves handy in multimedia section.
based Applications Some of real applications are: TimPlayer, cplay
etc.
3D CAD Applications Fandango is a real application which provides
full features of CAD.
Web Applications Python can also be used to develop web based
application. Some important developments are:
PythonWikiEngines, Pocoo,
PythonBlogSoftware etc.
Enterprise Applications Python can be used to create applications which
can be used within an Enterprise or an
Organization.
Some real time applications are: OpenErp,
Tryton, Picalo etc.
Applications for Images Using Python several application can be
developed for image. Applications developed
are: VPython, Gogh, imgSeek etc.
Python Example
• Python code is simple and easy to run.
• Here is a simple Python code that will print "Welcome to Python"
• A simple python example is given below.
Explanation:
• Here we are using IDLE to write the Python code. Detail explanation to run code
is given in Execute Python section.
• A variable is defined named "a" which holds "Welcome To Python".
• "print" statement is used to print the content. Therefore "print a" statement will
print the content of the variable.
• Therefore, the output "Welcome To Python" is produced.
In python 3.4 version, you need to add parenthesis () in a string code to print
it.
Algorithmic problem solving
• Algorithmic problems are problems where the solution involves the design of an
algorithm.
• Algorithmic problem solving is about the formulation and solution of such
problems.
• “algorithmic-problem solving”; this means solving problems that
require the formulation of an algorithm for their solution.
• On the other hand, it can be read as “algorithmic problem-solving”; this means
exploiting what has been learned from the experience of developing computer
software over the last 50 years that has helped us to hone our problem-solving
skills.
• The formulation of algorithms has always been an important element of
problem-solving.
• Algorithms are the end-product of the problem-solving process and it is
imperative that they are made explicit and are carefully studied.
• A particular focus has been on so-called “correct-by-construction” design
techniques.
• These techniques involve first formulating a mathematical specification of what
the algorithm is required to compute and then developing the algorithm in a way
that guarantees that it meets its specification.
• The process of formulating a specification involves abstraction from so-called
“real- world” problems; it helps to eliminate ambiguity and clarify the true
nature of the problem being tackled.
• Correct-by-construction is a systematic way of designing algorithms using the
specification as a blueprint;
• Roland Backhouse’s book on Algorithmic Problem Solving introduces the
principles underlying correct-by-construction design techniques.
• Problem solving is not easy.
• There are a number of mental processes at work during problem-solving. These
include:
• Perceptually recognizing a problem
• Representing the problem in memory
• Considering relevant information that applies to the current problem
• Identify different aspects of the problem
• Labeling and describing the problem
• According to by Tim Hicks published in The Business Journal of Sonoma/Marin. There
are seven-steps for an effective problem-solving process.
• Like the robots of Asimov, all recursive algorithms must obey three important laws:
Law 1:
• First, a base case is the condition that allows the algorithm to stop recursing.
• A base case is typically a problem that is small enough to solve directly.
• In the listsum algorithm the base case is a list of length 1.
Law 2:
• To obey the second law, we must arrange for a change of state that moves
the algorithm toward the base case.
• A change of state means that some data that the algorithm is using is modified.
• In the listsum algorithm our primary data structure is a list, so we must focus
our state-changing efforts on the list.
• Since the base case is a list of length 1, a natural progression toward the base case is
to shorten the list. This is exactly what actually done in the above example.
Law 3:
Tower of Hanoi
• Tower of Hanoi, is a mathematical puzzle which consists of three towers (pegs)
and more than one rings is as depicted −
• These rings are of different sizes and stacked upon in an ascending order, i.e. the
smaller one sits over the larger one.
Rules
• The mission is to move all the disks to some another tower without violating the
sequence of arrangement.
• A few rules to be followed for Tower of Hanoi are −
• Only one disk can be moved among the towers at any given time.
• Only the "top" disk can be removed.
• No large disk can sit over a small disk.
• Tower of Hanoi puzzle with n disks can be solved in minimum 2n−1 steps.
Algorithm
• To write an algorithm for Tower of Hanoi, first we need to learn how to solve
this
problem with lesser amount of disks, say → 1 or 2.
• We mark three towers with name, source, destinationand aux (only to help
moving the disks).
• If we have only one disk, then it can easily be moved from source to destination
peg.
If we have 2 disks −
Algorithm
Part A
• Define Algorithm.
• What are the primary factors needed to judge the quality of the algorithm?
• Time
• Memory
• Accuracy
• Sequence
• Generality
• Normal English
• Flowchart
• Pseudo code
• Decision table
• Program
• Sequence
• Selection
• Iteration
• Define Identifiers.
Identifier is the name given to entities like class, functions, variables etc. in Python. It
helps differentiating one entity from another. Identifiers are the names given to the
fundamental building blocks in a program. Some identifiers are built-in, and others
can be created by the programmer An identifier is a long sequence of characters and
numbers. Identifiers can be a combination of letters in lowercase (a to z) or uppercase
(A to Z) or digits (0 to 9) or an underscore (_).
• String literals
• Numeric literals
• Boolean literals
• Special literals
• Define List.
List contain 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.
• Define Pseudocode.
Pseudo code is an ordered version of your code written for human understanding
rather than machine understanding. Pseudo code is a formal design tool, developed
with the structured programming.The name itself specifies “Pseudo”
meansimitiation, “Code” means the set of statements or instructions written in a
programming language. Pseudo code is also called “Program Design Language
(PDL)”.
• Define Flowchart.
• Easy to Use
• Expressive Language
• Interpreted Language
• Cross-platform language
• Free and Open Source
• Object-Oriented language
• Extensible
• Large Standard Library
• GUI Programming
• Integrated
• Problem definition
• Development of a model
• Specification of Algorithm
• Designing an Algorithm
• Checking the correctness of Algorithm
• Analysis of Algorithm
• Implementation of Algorithm
• Program testing
• Documentation Preparation
• Define Iteration.
Computers are great at performing some task a million times very fast.
Iteration is the fancy term for repeating some programming commands
multiple times. Performing a task n number of times refers to iteration
• Define Recursion.
Part B.
• Explain Algorithms in details.
• What are the building blocks of algorithms. Exaplin each in detail.
• Define notation . what are the notations used in programming.
• Explain pseudo code in detail
• Explain flow chart in detail
• What is meant by programming language
• Discuss algorithmic problem solving
• Discuss the simple strategies for developing algorithms
• Define iteration. Explain in detail.
• Define recursion. Explain in detil.
• Illustrative problems: Write the algorithm, pseudo code and flowchart for find
minimum in a list
• Illustrative problems: Write the algorithm, pseudo code and flowchart for insert a
card in a list of sorted cards
• Illustrative problems: Write the algorithm, pseudo code and flowchart for guess
an integer number in a range,
• Illustrative problems: Write the algorithm, pseudo code and flowchart for
Towers of Hanoi.