Problem Analysis
Problem Analysis
1
‣ Arithmetic calculations
‣ Logical & Relational decisions
‣ Data manipulation, storage, & retrieval
6 IPO(S) Model
‣ Output
‣ Computer systems has the ability to present processed data in a
form that is understood by the users
‣ Example of output devices include: Screen/Monitor, Printer, and
Network
‣ Storage
‣ Computer systems has the ability to store data and programs
temporarily and permanently
‣ Random Access Memory (RAM) for short-term and temporary
storage
‣ Secondary storage devices like Hard Disk and USB for long-
term and permanent storage
7 Problem Solving
‣ Computers and associated programs are tools used to help in
solving scientific problems
‣ Steps for Problem Solving
‣ Analyse & Design:
‣ Clearly analyse and understand the requirements
‣ Design a sequential, step-wise approach to arrive at the
solution
‣ Implement & Test
‣ Implement the designed steps in a programming language
(ex. Python)
‣ Test the program for different input cases, to verify if all
requirements are met
‣ Maintain
‣ Modify if the problem domain or requirement changes
‣ Modify to improve performance
8 Analyse & Design
1 ‣ As a first step towards problem solving, we need to:
‣ Clearly understand the problem and list out:
‣ Required INPUTS
‣ PROCESS to arrive at the solution – Write an Algorithm
‣ Expected results or OUTPUT for the input and process
‣ An Algorithm
2
1
12
19
2. Write “Enter 3 numbers: ”
3. Read number1, number2, number3
4. average = (number1 + number2 + number3) / 3
5. Write “Average is: ” +average
6. Stop
19 Class Work
‣ Problem: Write an algorithm to determine and display the area of a
triangle where the base and height is given by the user. Ensure to
show the result as “Area = nnn”.
‣ Inputs: ?
‣ Output: ?
‣ Algorithm: Complete the algorithm and walkthrough with different
inputs to check the validity of the algorithm.
20 Class Work
‣ What would be the output of the following algorithm?
‣ Algorithm
1. Start
2. number1 = number2 = number3 = 0
3. number1 = 3
4. number2 = number1 * 4
5. number1 = number2
6. number3 = number3 + number2 + number1
7. Write number1
8. Write number2
9. Write number3
10. Stop
21 Class Work
‣ What would be the output of the following algorithm?
‣ Algorithm
1. Start
2. number1 = 0
3. number2 = 0
4. number3 = 0
5. number4 = 0
6. number1 = 2
7. number2 = number1 * 2
8. number3 = number2 + number1 * 4
9. number4 = (number2 + number1) * 4
10. Write number3
22
9. number4 = (number2 + number1) * 4
10. Write number3
11. Write number4
12. Stop
22 Class Work
‣ Problem: Write an algorithm to evaluate the expression: f(x) =
15x2 + 4x + 2.
‣ Inputs: ?
‣ Output: ?
‣ Algorithm: Complete the algorithm and walkthrough with different
inputs to check the validity of the algorithm.
23 PyCharm
An IDE for writing Python Programs
24 Download Python 3
‣ Navigate to https://www.python.org/ on your browser.
‣ Click on downloads in the menu and click on Python 3.x
25 Download Python 3
‣ Click on downloads in the menu and click on Python 3.x
‣ Once downloaded, install the package.
26 Download IDE
‣ Navigate to https://www.jetbrains.com/pycharm/ on your browser
27 Community Version – Open Source
28 Download and Install
29 Add to Applications
30 Start PyCharm
‣ Open the PyCharm application
‣ Create a New Project
31 MyFirstProject
32 MyFirstProject
33 Create a Python File
34 Write a Run a Python Program
35 Algorithms to Programs
Basic Python statements
36
1
33
34
35
Basic Python statements
36 Learning Python
1 ‣ Write an algorithm to display a message.
‣ Algorithm
1. Start
2. Write “Hello, How are you?”
3. Stop
2 ‣ Python
# Print a String
def main():
print("Hello how are you?”)
main()
37 Learning Python
1 ‣ Write an algorithm to add two numbers, 8 and -2
‣ Algorithm
1. Start
2. Write 8 + (-2)// 6
3. Write (“8+(-2)”//8+(-2))
4. Stop
Add 8+(-2)
Between ”” print as it is
2 ‣ Python
# Addition
def main():
print(8 + (-2))
print("8 + (-2)”)
Main()
def main():
name = input("Enter name: ")
print("Hello “ + name + “ nice to meet you.”)
Main()
The output:
‣
number1 =int(input("enter first number"))
number2 = int(input("enter second number"))
result= number1 + number2
print("sum is", result)
‣
‣ The output is
‣ enter first number 3
‣ enter second number 5
‣ sum is 8
‣ OR
‣ number1 =int(input("enter first number"))
number2 = int(input("enter second number"))
print(number1+number2)
print("number1+number2")
result= number1 + number2
print("sum is", result)
‣ Output:
‣ enter first number4
‣ enter second number5
‣ 9
‣ number1+number2
‣ sum is 9
40 Learning Python
1 ‣ Write an algorithm to determine and display the square and cube
of a number.
‣ Algorithm
1. Start
2. Write “Enter a number: ”
3. Read number1
4. square = number1 * number1
5. cube = number1 * number1 * number1
6. Write “Square is: ” + square
7. Write “Cube is: ” + cube
8. Stop
2 ‣ Python
‣ # Program to find square and cube of a user given number
‣
number1= int(input("enter a number:"))
square= number1*number1
cube= number1*number1*number1
2
square= number1*number1
cube= number1*number1*number1
print("square is", square)
print("cube is", cube)
‣ Output:
‣ enter a number:3
‣ square is 9
‣ cube is 27
41 In Summary
‣ The IPO(S) model describes how problems are solved by
computers
‣ The different stages of problem solving
‣ Analysis and Algorithm Design
‣ Implementation and Testing
‣ Maintenance
‣ Algorithms are step-by-step process to solve a given problem.
‣ Read/Write
‣ Assignment statements
‣ Variables
‣ Precedence of Arithmetic Operators
‣ Install PyCharm IDE and run a python program
‣ Exercise basic Python syntax