Uploaded by madiha786382

Week 3 Flowchats,algorithms

advertisement
Programming Logic
Learning Objectives
•
Understand and implement flow chart
diagrams
for
any
given
problem.
•
•
Write algorithm of any given problem.
Develop
problem
solving
Computer Science Department, UET Lahore.
skills
What is an Algorithm?
● Algorithm is a finite set of steps which are used to
solve a problem.
● It is a way to describe the steps you will be following to
solve any problem, usually written in pseudocode.
Computer Science Department, UET Lahore.
Why?
● To simplify the solution of our problem.
● Create a roadmap/flow to carry out each
process.
•
Identify inputs and outputs.
•
Ease for programming.
Computer Science Department, UET Lahore.
Example
● You go through series of steps while making a
transaction from an ATM
1. Insert card
2. Input pin and amount
Computer Science Department, UET Lahore.
3. Take money
Flowchart
• Flowcharts are used to represent the flow
of an algorithm.
• The steps of the process is shown by
boxes and its flow is represented by
connecting arrows.
Computer Science Department, UET Lahore.
Flowchart Symbols
● Different symbols have different meanings.
Some of the common symbols are shown below:
1.
The Oval
To represent Start or end of the algorithm.
Computer Science Department, UET Lahore.
Flowchart Symbols
● Different symbols have different meanings.
Some of the common symbols are shown below:
2.
The Rectangle
One step is represented by a rectangle.
Computer Science Department, UET Lahore.
Flowchart Symbols
● Different symbols have different meanings.
Some of the common symbols are shown below:
3.
The Diamond
Used while making some decision.
Computer Science Department, UET Lahore.
Flowchart Symbols
● Different symbols have different meanings.
Some of the common symbols are shown below:
4.
The Arrow
To show the flow of the process
flow
Computer Science Department, UET Lahore.
Flowchart Symbols
● Different symbols have different meanings.
Some of the common symbols are shown below:
5.
The Parallelogram
To represent the input and output
Input
Computer Science Department, UET Lahore.
Output
Example
Make a flowchart that takes two
values from the user and print the
greater number.
Step 1: Start
Step 2: input number1
Step 3: input number2
Step 4: if number1 is greater than number2
Print “number1 is greater”
else
print “number2 is greater”
Step 5: Stop
Computer Science Department, UET Lahore.
Program Structure in Python:
#Some programs discussed in last lecture
num1=5
num2=10
addition=num1+num2
variables
Operation
print(“My first python code”)
num=int(input("Enter number"))
square=num*2
Computer Science Department, UET Lahore.
Values assigned
to variable
Program Structure in Python:
#Some programs discussed in last lecture
num1=5
num2=10
addition=num1+num2
print(“Hello World”)
num=int(input("Enter number"))
square=num*2
Computer Science Department, UET Lahore.
Function to
display
content on
console
Program Structure in Python:
#Some programs discussed in last lecture
num1=5
num2=10
addition=num1+num2
print(“Hello Word”)
num=int(input("Enter number"))
square=num*2
Computer Science Department, UET Lahore.
Function to
takeConverting
input
user
input into
from user
integer
comment
Activity
1. Write an algorithm of your admission process in UET
2. Make a flowchart for this process.
3. Write a code that takes five number as input
from user.
● Print the numbers
● Find mean and print it as well.
Computer Science Department, UET Lahore.
Activity
1. Write an algorithm and code from the given flowchart
Computer Science Department, UET Lahore.
Learning Objective
In this lecture, we learned about algorithm
designing, making flowcharts, meaning of
different shapes in flowcharts, and writing
programs in python.
Computer Science Department, UET Lahore.
Conclusion
● Algorithms help us in solving problems by
creating different steps.
● Algorithms are not programming codes.
● Flowcharts are used to represent each step
of a process in the form of blocks.
● Every shape has different meaning in
flowcharts.
● In python,the program contains variables,
functions and operations.
Computer Science Department, UET Lahore.
Take Home Tasks
1. Find out about different writing styles of
algorithms
2. Find out about different shapes of flowcharts and
their usage.
3. Maria has 4 bags while going to airport, she has
been told that she can take an average of 50kg.Tell
her to input the weights of each bag and calculate
the mean weight.
Computer Science Department, UET Lahore.
Download