0% found this document useful (0 votes)
29 views

Week 3 Flowchats, Algorithms

This document discusses programming logic and algorithms. It defines an algorithm as a set of steps to solve a problem and explains why algorithms are useful for simplifying solutions, creating a process roadmap, and identifying inputs and outputs. The document provides examples of algorithms and flowcharts, including steps for an ATM transaction. It also discusses writing algorithms, using different flowchart symbols, and the structure of Python programs with variables, functions, and operations.

Uploaded by

Fardeen Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Week 3 Flowchats, Algorithms

This document discusses programming logic and algorithms. It defines an algorithm as a set of steps to solve a problem and explains why algorithms are useful for simplifying solutions, creating a process roadmap, and identifying inputs and outputs. The document provides examples of algorithms and flowcharts, including steps for an ATM transaction. It also discusses writing algorithms, using different flowchart symbols, and the structure of Python programs with variables, functions, and operations.

Uploaded by

Fardeen Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Programming Logic

Learning Objectives

• Understand and implement flow chart


diagrams for any given problem.

• Write algorithm of any given problem.

• Develop problem solving skills

Computer Science Department, UET Lahore.


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 3. Take money


Computer Science Department, UET Lahore.
Writing an Algorithm
● Write all the possible steps in simple language
● For example, steps of Transaction from ATM are:
Step 1. Insert card

Step 2. Input pin number

Step 3. Enter amount

Step 4. Take money

Computer Science Department, UET Lahore.


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 Output

Computer Science Department, UET Lahore.


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 variables
Values assigned
num2=10 to variable
Operation
addition=num1+num2

print(“My first python code”)


num=int(input("Enter number"))
square=num*2

Computer Science Department, UET Lahore.


Program Structure in Python:
#Some programs discussed in last lecture

num1=5
num2=10
addition=num1+num2
Function to
print(“Hello World”) display
content on
console
num=int(input("Enter number"))
square=num*2

Computer Science Department, UET Lahore.


Program Structure in Python:
#Some programs discussed in last lecture
comment

num1=5
num2=10
addition=num1+num2

print(“Hello Word”)
num=int(input("Enter number")) Function to
takeConverting
input
square=num*2 user
from userinput into
integer

Computer Science Department, UET Lahore.


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.

You might also like