python moule 1
python moule 1
Course Code
CSE1021
Introduction to Problem Solving and
Programming
Lecture -1 Credits 4
Unit -1
(8-Hours)
VIT Bhopal
01
Unit
Introduction to Computer Problem
Solving
Mapping Course outcome
ASSESMENT DETAILS
Unit -1
Introduction to Computer Problem Solving:
Algorithm Development
Flowcharting
Program Coding
Documentation
N1 = int(input("enter the first no:"))
N2 = int(input("enter the second no:"))
subtraction = N1 - N2
print("the sum is:",subtraction)
Problem Analysis
• Process of becoming familiar with the problem.
Step 3: Add two numbers x and y; store the value in variable sum
Step 4: If you want to try again with different numbers then goto step 2
else
goto step 5
Step 5: END
●
An algorithm to find sum of two
Step 1: Start
numbers:
Step 2: Declare variables num1, num2 and sum. Step 3: Read
values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum Step 6: Stop
Flowcharting
• Graphical representation of an algorithm using standard symbols.
• Includes a set of various standard shaped boxes that are
interconnected by flow lines.
C=A+B Processing
• Coding isn’t the only task to be done to solve a problem using computer.
• The program may ask user for inputs and generates outputs
after processing the inputs.
Debugging and Testing
• Testing ensures that program performs correctly the required task.
● Low-level
– Machine Level
– Assembly Level
Problem Solving
● Solving problems is the core of computer science.
Advantages Disadvantages
Easy to use More execution time
Portability Needs own translator
Easy Debugging
Easy and Fast Development of
software
Compiler
• A high level source program must be translated into a form machine can
understand. This done by software called the compiler.
• In case of any error, the computer generates message about the error.
A software program is
needed to handle the lights in
a concert stadium. There are
hundreds of lights, all
producing complicated
sequences and effects.
Approach
Before a single line of code is
written, a structure chart is
drawn. Something like this:
Conti….
• A 'module' is ideally a self-contained block of
code.
• The code within has a clearly defined set of inputs
and outputs, this is called an 'interface'.
• Each module has a specific function to perform.
Its actions are controlled by a master program
loop.
• This is like the conductor in an orchestra, making
the whole thing work in harmony.
Conti..
● The control module is concerned with
controlling the hardware. It does this by
communicating and controlling a number
of sub-modules.
● These sub-modules are responsible for
certain types of light.
What is an ● It is a step-by-step
algorithm? instruction for solving a
▪ An algorithm defined as a particular task in finite
sequence of definite and amount of time.
effective instructions, which
terminates with production
of correct output with given
input. • Algorithm is an effective
method for solving a problem
expressed as finite sequence
of instructions.
Writing the
Algorithm
● Algorithm is generally ● Sometimes algorithms are
developed before the actual written using pseudocodes,
coding is done. i.e. a language similar to the
● It is written using English programming language to be
like language so that it is used.
easily understandable even
by non-programmers.
Writing algorithm for solving a
problem offers these advantages
−
● Promotes effective communication between team
members
● Enables analysis of problem at hand
● Acts as blueprint for coding
● Assists in debugging
● Becomes part of software documentation for future
reference during maintenance phase
characteristics of a good and
correct algorithm −
● Has a set of inputs
● Steps are uniquely defined
● Has finite number of steps
● Produces desired output
Here is the algorithm for going to
the market to purchase a pen.
Step 1:- Get dressed to go to market.
Step 2:- Check your wallet for money.
Step 3:- is there is no money in the wallet replenish it.
Step 4:- Go to the shop.
Step 5:- Ask for your favorite brand of pen.
Step 6:- If pen is not available, go to step 7else to step 10.
Step 7:- Give money to shopkeeper.
Step 8:- Keep the purchased pen safely.
Step 9:- Go back to home.
Step 10:- Ask for other brand of pen.
Step 11:- Go to Step 7.
Let us now create an algorithm to
check whether a number is positive
or negative.
A flow chart is a
step by step diagrammatic representation of the logic paths to
•
given problem.
help a great deal to analyze the problem and plan its solution in
•
Oval:
Also called ‘Terminator’ symbol. Used to
indicate start and end of the flow.
Process:
Also called ‘Action’ symbol. It indicates a
process action such as for storing
arithmetic operations.
Decision Maker:
A decision or branching point, usually a
yes/no or true/false question is asked, and
based on the answer, the path gets split
into two branches.
SYMBOLS USED IN FLOW CHART
Que: Draw a flowchart to find out the biggest of the three unequal positive
numbers.
PseudoCode
PSEUDO CODE
● INPUT
● COMPUTE
● PRINT
● INCREMENT
● DECREMENT
● IF/ELSE
● WHILE
● TRUE/FALSE
An imperative language uses a sequence of statements to determine how
to reach a certain goal.
4. CSS 5. Java
What this language is used for: 6. SQL
What this language is used for: What this language is used for:
Web documents E-commerce
Website development Database management
Finance Sales reports
Website design App development Business management
Program verification
● A formal proof system for proving programs correct.
● A proof can provide confidence of correctness in a situation where exhaustive
semantic checking is time-consuming or impossible
Errors Checked by Compiler:-
Syntax errors:
● Errors that occur when you violate the rules of writing C/C++ syntax are known as
syntax errors. This compiler error indicates something that must be fixed before the
code can be compiled. All these errors are detected by compiler and thus are known
as compile-time errors.
Most frequent syntax errors are:
○ Missing Parenthesis (})
Do you have
any
questions?