Page 268 - Computer Science V2.0 Class 11
P. 268
10.1.3 Iterative Flow
Executing an instruction (Python statement) or a sequence of instructions multiple times is called iteration, or looping.
The number of times a sequence of the statement(s) gets executed may be fixed beforehand or may depend on a
condition. We will discuss iterations in more detail in the next chapter.
10.2 Types of Statements in Python
A statement is an instruction given to the computer to perform a particular task. It is the smallest executable unit of a
program. There are three types of statements in Python:
10.2.1 Simple Statements
A simple statement appears by itself in a line. However, Python allows several statements in a single line, separated
by semicolons. The assignment statement, input and output statements are examples of simple statements. An
expression by itself is also a simple statement and is called an expression statement. You will learn about more
simple statements as you progress through your journey of Python programming. Next, we give some examples of
simple statements:
>>> name = 'Bharati'
>>> print('Good morning,', name)
Good morning, Bharati
>>> length = 50
>>> breadth = 40
>>> area = length * breadth
>>> print('area=',area)
area=2000
10.2.2 Compound Statements
A compound statement often spans several lines. It comprises one or more header clauses and one or more sequences
of statements, called suites. A header clause begins with a keyword and ends with a colon. A suite may comprise
one or more statements. The suite, following a header clause, appears at the next level of indentation. For example,
consider the following program segment:
01 marks = 44
02 passMarks = 33
03 if marks >= passMarks:
04 print("Passed")
05 print("Congratulations")
06 else:
07 print("Failed")
Note that the header clauses
if marks >= passMarks:
and
else:
appears at the same level of indentation. The header clause:
if marks >= passMarks:
is followed by a suite (sequence of statements) at the next level of indentation (following the header clause):
print("Passed")
print("congratulations")
Next is
else:
254 Touchpad Computer Science (Ver. 2.0)-XI

