Page 95 - Computer Science Class 11 With Functions
P. 95
time = int(input('enter time in years: '))
interest = principal * rate * time /100
print('principal = ', principal, 'rate = ', rate,\
'time = ', time, 'interest = ', round(interest))
Do not worry if you do not understand the above code, as we will discuss the subject of Python programming in the
subsequent chapters of this book.
In the above algorithm (or, equivalently, the Python program), the steps are executed in the same order as they appear.
Such a program is called a straight-line program. But in real life, instructions may be executed or skipped depending on
one or more conditions. For example, one may want to buy a Maruti car, only if a discount of at least 10% is allowed to
be applied on the original price. Fig 4.3 shows a flowchart that depicts the process of buying a car conditionally.
Sequential flow (straight-line program): Includes a sequence of instructions that are executed exactly once in the
same sequence in which they appear.
Start
No
discount>=10% Don't buy a car
Yes
Buy a car
Stop
Fig 4.3: Flowchart to decide whether to buy a car
Next, we describe an algorithm to decide whether to buy a car:
1. if discount >= 10% then buy a car
2. Otherwise do not buy a car
Fig 4.3 Algorithm to decide whether to buy a car.
In this chapter, so far, we have used the term "algorithm" in the context of the solution of a non-computational
problem. However, the steps in the algorithmic description of a computational problem are quite close to the steps
in a program written in a programming language. As it is still not a perfect program in a programming language, it is
called a pseudocode.
Next, we discuss the problem of issuing a Voter's ID card (see flowchart in Fig 4.4). Before issuing the voter's ID card,
it must be checked that the person has attained the age of 18 years. If the person has reached the age of 18 years,
he/she is issued the voter's ID, otherwise, the voter's ID is denied.
Problem Solving 93

