0% found this document useful (0 votes)
20 views31 pages

Tutorial1ProblemSolvingSkills2 2d5093b0 998f 4cb2 b339 7febeaede4fa 95176

The document serves as an introductory tutorial on programming and problem-solving skills, covering logical thinking, algorithms, pseudo-code, flowcharts, and flow of control. It outlines a methodological approach to problem-solving in programming, emphasizing the importance of analyzing problems, developing algorithms, coding, and testing. Additionally, it provides exercises and examples to reinforce the concepts discussed.

Uploaded by

sthkrish90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views31 pages

Tutorial1ProblemSolvingSkills2 2d5093b0 998f 4cb2 b339 7febeaede4fa 95176

The document serves as an introductory tutorial on programming and problem-solving skills, covering logical thinking, algorithms, pseudo-code, flowcharts, and flow of control. It outlines a methodological approach to problem-solving in programming, emphasizing the importance of analyzing problems, developing algorithms, coding, and testing. Additionally, it provides exercises and examples to reinforce the concepts discussed.

Uploaded by

sthkrish90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Introductory To

Programming and
Problem-Solving Skills
Tutorial Week -
1
Agenda
• Logical Thinking Ideas
• A methodological approach
• Algorithm
• Pseudo-Code
• Flowchart
• Flow of Control
• Exercises

2
Let’s think logically
Let’s play the game
https://www.proprofsgames.com/wolf-sheep-and-cabbage/

3
Logical thinking ideas
[Scenario]: Imagine hearing a sound of water dripping from faucet and
realize that there is a leaky faucet at home. May be at first we will try
to fix the problem by our own but incase the problem cannot be
solved by us, then we simply turn off the water and call the plumber.
The plumber will analyze the problem to identify the source of water
leakage, make a plan about the work to fix the water leakage and fix it.
From above example, it is explicit that, finding a solution to a problem
might consist of multiple steps. For simpler problems we can easily
find a solution but complex problems requires a methodical approach.

In programming also, we follow steps for problem solving.


4
A methodological approach
• As discussed earlier, easy problem could be easily solved but for
complex problems we need to follow methodological approach. In
computer science, methodological approach follows four steps:

1. Analyzing the Problem


2. Developing an Algorithm
3. Coding
4. Testing and Debugging

Remember: It is good practice to develop algorithm before jumping into coding. 5


Let’s learn and implement

6
Algorithm
What is an Algorithm?
⮚ An algorithm is a finite number of clearly
described steps that can be followed to
produce a desired result for a given
input in a finite amount of time (that is, it
eventually terminates)
7
Characteristics of a good algorithm
• Precision – the steps are precisely stated or defined.
• Uniqueness – results of each steps are uniquely defined and only
depends on the input and the result of the preceding steps.
• Finiteness – the algorithm must stop eventually.
• Input – the algorithm receives some input.
• Output – the algorithm produces desired output.

User Processing or Desired


Input computation Output
8
Example 1
Write an algorithm to find the sum of two numbers.
Step 1: Start
Step 2: Input two number and store it to num1 and num2
Step 3: Compute num1 + num2 and store it in addition
Step 4: Display addition
Step 5: End

9
For You
1. Write an algorithm to find the square of a number.
Solution
Step 1: Start
Step 2: Input a number and store it to num
Step 3: Compute num * num and store it to square
Step 4: Print square
Step 5: End
10
11
Pseudo-code
What is a Pseudo-code?
Pseudo-code is another way of representing
an algorithm which is considered as non
formal language that provides detailed
instruction for computer to follow, but
cannot be directly executed.
12
Pseudocode Keywords
• Some of the frequently used keywords while writing pseudo-code:
1. INPUT
2. COMPUTE
3. PRINT
4. INCREMENT
5. DECREMENT
6. IF/ELSE
7. WHILE
8. TRUE/FALSE
13
Example 2
Write an pseudocode to find the sum of two numbers.

Begin
SET sum =0
INPUT num1, num2
COMPUTE sum = num1 + num2
PRINT sum
End
14
For You
1. Write a pseudocode to find the area of rectangle
Solution
Begin
INPUT length, breadth
COMPUTE areaOfRect = length * breadth
PRINT areaOfRect
End
15
Now moving on to next
programming tool

16
Flowchart
What is a Flowchart?
A flowchart is graphical or diagrammatic
representation of algorithm, basically sequence
of any problem to be solved by computer
programming language.

There are standardised symbols to draw flowcharts. 17


But what might be
the symbols used in
flowchart?

18
Basic Flowchart Symbols
Flowchart Symbol Function Description
Start/End It indicates where the flow starts and ends.
Also known as terminator.
Process Also called “Action Symbol,” it represents a
process, action or a single step
Decision A decision or branching point, usually a
yes/no or true/false question is asked and
based on that, the path gets split into two
branches
Input/ Output Also called as data symbol, this parallelogram
shape is used to input or output data.
Arrow Line Connector to show the flow between
shapes.

19
Flowchart Symbols Cont.

20
Example 3
Draw a flowchart of the sum of two numbers.

21
For You
1. Draw a flowchart of the area of rectangle

22
Flow of Control
• As previously discussed, the flow of control
depicts the flow of events as represented in
the flow chart. The events can flow in a
sequence, or on branch based on a decision
or even repeat some part for a finite number
of times. Such flow of control is denoted as
sequence, selection and repetition.
23
Flow of Control – Sequence control structure
Begin

Statement 1
Read birth date

Statement 2
Calculate
Age = current year – birth date

Statement 3
Display
age
:

End

24
Flow of Control – Selection control structure

Begin

No Yes
Condition Read age

YES N
Age > 55?
O
else- then-
statement(s) statement(s) print “Non-
print “Pension” pension”

End

25
Flow of Control – Repetition control structure

yes Loop
Condition
Statement(s)
no

26
Using Algorithm and Flowchart in Coding
Algorithm Flowchart Coding

# Prompt the user to enter the first number


num1 = float(input("Enter the first number: "))

# Prompt the user to enter the second number


num2 = float(input("Enter the second number: "))

# Add the two numbers together


result = num1 + num2

# Print the result to the user


print(f"The sum of {num1} and {num2} is {result}”)

27
For You – Exercise
1. Write an pseudocode and flowchart that will accept/read two numbers and
then display the bigger number.
2. Write an pseudocode and flowchart to find whether the number is even or
not.
3. Write a pseudocode and draw a flowchart to check whether a person is
either child or teenage or adult. (Hint: child(<13), teenager(>=13 but <20)
or adult(>=20)).
4. Create an algorithm and a flowchart that will compute the sum of two
numbers. If the sum is below or equal to twenty, two number will be
entered again. If the sum is above 20, it will display sum.

28
For You – Additional Questions
• Two friends decide who gets the last slice of a cake by flipping a coin five
times. The first person to win three flips wins the cake. An input of 1 means
player 1 wins a flip, and a 2 means player 2 wins a flip. Design an algorithm to
determine who takes the cake?

• Write pseudocode that will perform the following:


a) Read the marks of three subjects: Computer Science,Mathematics and
Physics, out of 100
b) Calculate the aggregate marks
c) Calculate the percentage of marks

29
For You – Home Task
• Create an algorithm and a flowchart that will output the factorial
of a given number.

• Create an algorithm and a flowchart that will output the Fibonacci


series up to a given number.

• Create an algorithm and a flowchart that will output all the prime
numbers between 2 numbers.

30
31

You might also like