Page 492 - ComputerScience_Class_11
P. 492
Importance of Sequential Flow of Control
The importance of sequential flow of control is as follows:
• Basic structure: Sequential flow is the most basic and intuitive way for a program to run. It’s the foundation of more
complex flows like loops and conditionals.
• Simple programs: For simple programs that don’t require decisions or repetitions, sequential flow is enough to
achieve the desired result.
• Understanding program logic: Sequential flow helps beginners understand how instructions are processed in
Python and prepares them for more complex control structures.
Let’s consider an example to understand sequential flow in detail.
Program 1: Calculate the compound interest by accepting principal, rate and time.
Program 1.py
File Edit Format Run Options Window Help
p=float(input('Enter the principal: '))
r=float(input('Enter rate of interest: '))
t=float(input('Enter time duration in years: '))
ci=p*((1+r/100)**t)-p
print('Compound Interest:',ci)
Output
Enter the principal: 5000
Enter rate of interest: 7.5
Enter time duration in years: 5
Compound Interest: 2178.1466308593735
The first line is executed, followed by second line until we come to the last print() statement line which prints the
output.
12.3.2 Conditional Flow of Control
Conditional flow of control allows a program to make decisions based on certain conditions. This type of control
lets the program choose different paths of execution depending on whether a condition is True or False. In Python,
conditional statements are used to implement conditional flow.
Conditional flow can be of following types:
• The if Statement
• The if-else Statement
• The elif Statement
• The Nested if Statement
The if Statement
The if statement is one of the most fundamental control structures in Python, allowing the program to make decisions
based on a condition. It evaluates an expression (condition) and if that condition is True, the code inside the if block
will be executed. If the condition is False, the code inside the if block is skipped.
490 Touchpad Computer Science (Ver. 3.0)-XI

