Cs CHP 4 - Unlocked 1
Cs CHP 4 - Unlocked 1
1. Empty Statement
The simplest statement is the empty statement i.e., a statement which does nothing. In Python empty
statement is pass statement. It takes the following form :
Pass
2. Simple Statement
Any single executable statement is a simple statement in Python. For Example, following is a simple
statement in Python :
name = input(" your name")
3. Compound Statement
A compound statement represents a group of statements executed as a unit. The compound state
ments of Python are written in a specific pattern as shown below :
<compound statement header> :
<indented body containing multiple simple and/or compound statements>
That is, a compound statement has :
* a header line which begins with a keyword and ends with a colon
* a body consisting of one or more Python statements, each indented inside the header line.
All statements in the body are at the same level of indentation.
Sequence
The sequence construct means the statements are being executed sequentially. This represents the
default flow of statement
Selection
The selection construct means the execution of statement (s) depending upon a condition-test. If a
condition evaluates to True, a course-of-action (a set of statements) is followed otherwise another
course-of-action (a different set of statements) is followed. This construct (selection construct) is
also called decision construct because it helps in making decision about which set-of-statements is
to be executed.
Iteration
The integration constructs mean repetition of a set-of-statement upon a condition-test. Till the time a
condition is True (or False depending upon the loop), a set-of-statement are repeated again and
again. As soon as the condition becomes False (or True), the repetition stops. The iteration con
struct is also called looping construct. The set-of-statements that are repeated again and again is
called the body the loop. Then on which the execution or exit of the loop depends is called the exit
condition or test-condition.
Flowcharts
A flow chat is a graphical representation of an algorithm. Aflowchart shows different subtasks with
different symboles.
Process Decision
Subprocess Start/End
Document Data
* Use Data symbole for Input/output (I/O) operation (taking input and showing output).
* Use Process symbol for any type of computation and internal operations like initialization,
calculation etc.
* Use Subprocess symbol to invoke a procedure written already.
Pseudocode
Pseudo code is an informal language that helps programmers describe steps of a program’s solution
without using any programming language syntax. Pseudo code is an informal way of describing the
steps of a program’s solution without using any strict programming language syntax or
underlying technology considerations.
Decision Trees
Decision trees are a way of presenting rules in a hierarchical and sequential structure, where based
on the hierarchy of rules, certain outcomes are predicted.
Marks Division
60 First
50 − 60 Second
40 − 50 Third
40 Failed
The if statements of Python
The if statements are the conditional statements in Python and these implement selection constructs
(decision constructs). An if statement tests a particular condition; if the condition evaluates to true, a
course-of-action is followed i.e., a statement or set-of-statements is executed. Otherwise (if the
condition evaluates to false), the course-of action is ignored.
You can see that in and not in are the operaors that check for membership of a value inside a
sequence. Thus, in and not in are also called membership operators. These operators work with all
sequence types i.e., strings, tuples and lists etc.
Iteration/Looping statements
The iteration statements or repetition statements allow a set of instructions to be performed repeat
edly until a certain condition is fulfilled. The interation statements are also called loops or looping
Statements. Python provides two kinds of loops : for loop and while loop to represent two
categories of loops, which are :
* counting loops the loops that repeat a certain number of times ; Python’s for loops is a
counting loop.
* conditional loops the loops that repeat until a certain thing happens i.e., they keep repeating
as long as some condition is true ; Python’s while loop is a conditional loop.
<sequence>
statements_to_repeat
a=2
print(a) terminated through a break statement
a* = 2
if a 100 :
break
Complete syntax of Python loops along with else clause is as given below :
else : else :
statement(s) statement(s)
Nested Loops
A loop may contain another loop in its body. This form of a loop is called nested loop. But in a
nested loop, the inner loop must terminate before the outer loop.