Unit 1
Unit 1
Q1. Define Problem. What are steps in problem solving? Definition of problem
Problem is defined as a situation or issue or condition which needs to be solve to achieve a specific
goal.
Steps in problem solving
1. Identify the problem - You need to be clear about what exactly the problem is. If the problem is
not identified then it cannot be solved. example- when you want to learn a language then first
identify which language do you want to learn
2. Understand the problem - Here problem should be defined properly so that it helps in
understanding the problem more. It helps to understand knowledge base of the problem. It helps in
finding a target for what you want to achieve.
3. Identify alternative ways to solve the problem - This step is very crucial because until and unless
we explore all options, finding a correct solution is next to possible. This involves the process to
create a list of solutions.
4. Select the best way to solve the problem - Identify and evaluate pros and cons of each possible
Problem Definition:
Before a program is written for solving a problem, it is important to define the problem
clearly.
Define problem: Problem is defined as a situation or issue or condition which needs to
solve to achieve the goal.
For most of the software projects, the system analyst approach system users to collect user
requirements and define the problem that the system aims to solve.
System analyst typically looks at following issues:
o What input is required for achieving expected output?
Divides a problem into smaller units and then Starts from solving small modules and
solve it. adding them up together.
Structured programming languages such as C use OOP languages like C++ and Java,
top-down approach. etc. uses bottom-up mechanism.
Requirement Analysis: In this phase, the user’s expectations are gathered to know why the
software has to be built. The gathered requirements are analyzed to decide scope of software. The
last activity in this phase includes documenting every identified requirement of the users in order
to avoid any doubts regarding functionality of software. The functionality, capability, performance
and availability of hardware and software components are all analyzed in this phase.
Design: The requirements documented in previous phase act as an input to the design phase. In
the design phase, core structure of the software is broken down into modules. The solution of the
program is specified for each module in the form of algorithms or flowcharts.
Implementation: In this phase, the designed algorithms are converted into program code using
Maintenance: Maintenance and enhancement are ongoing activities that are done to cope with
newly discovered problems or new requirements. Such activities may take a long time to complete
as the requirement may call for the addition of new code that does not fit original design or an extra
piece of code, required to fix an unforeseen problem.
4. Python Tuple
Tuple is an ordered sequence of items same as list.The only difference is that tuples are
immutable. Tuples once created cannot be modified.
It is defined within parentheses () where items are separated by commas.
Ex: t = (5,'program', 1+3j)
5. Dictionary
Dictionary is an unordered collection of items in key:value pair of any type. In dictionary values
are separated by comma inside braces { }. ·
In dictionary, key should be unique.
Ex: a = {‘name’:’Bob’,’Age’: 21}
input (expression)
2. print()
We use the print() function to output data to the standard output device (screen). print()
evaluates the expression before printing it on the monitor. Print statement outputs an entire
(complete) line and then goes to next line for subsequent output (s). To print more than one item
on a single line, comma (,) may be used.
Syntax:
print (expression/constant/variable)
Example:
def info(self):
print("Hello, % s. You are % s old." % (self.name, self.age))
Output:
Hello, John. You are 43 old.
Hello, Hilbert. You are 16 old.
Hello, Alice. You are 30 old.
# modularization is done by
# functional approach
def sum_the_list(mylist):
res = 0
for val in mylist:
res += val
return res
print(sum_the_list(mylist))
Output:
100
if len(mylist) == 1:
return mylist[0]
else:
return mylist[0] + sum_the_list(mylist[1:])
Output:
110