Chapter 11 Conditional and Looping Constructs Solutions
Question - 11 : - Write the syntax of a while loop.
Answer - 11 : -
The syntax of a while loop in Python programming language is :
while expression :
statement(s)
Question - 12 : - What happened when the condition of while loop becomes false ?
Answer - 12 : -
When the condition becomes false, program control passes to the line immediately following the loop.
Question - 13 : - Write the syntax of a for loop.
Answer - 13 : -
The syntax of a for loop look is as follows:
for iterating_var in sequence :
statements(s)
Question - 14 : - What do you mean by “continue statement” ?
Answer - 14 : -
It causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
Question - 15 : - What do you mean by “pass statement” ?
Answer - 15 : -
The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute.
Question - 16 : - Write the syntax of “break” statement.
Answer - 16 : -
The syntax for a break statement in Python is as follows : break
Question - 17 : - What is a statement ? What is the significance of an empty statement ?
Answer - 17 : -
A statement is an instruction given to the computer to perform any kind of action.
An empty statement is useful in situations where the code requires a statement but does not require logic. To fill these two requirements simultaneously, empty statement is used. Python offers ‘pass’ statement as an empty statement.
Question - 18 : - What is the difference between determinable loop and non-determinable loop ?
Answer - 18 : -
The ‘for loop’ can be labelled as ‘determinable
Ans. Value of expression is 100 Good bye!
loop’ as number of its iterations can be determined before-hand as the size of the sequence, it is operating upon.
The ‘while loop’ can be ‘non-determined loop’ as its number of iterations cannot be determined before-hand. Its iterations depend upon the result of a test-condition, which cannot be determined before-hand.
Question - 19 : - Explain nested if…. else.
Answer - 19 : -
There may be a situation when you want to check for another condition after a condition resolves to true. In such a situation, you can use the nested if construct. In a nested if construct, you can have an if…elif…else construct inside another if…elif… else construct
Question - 20 : - Write the syntax of a for loop and also given an example.
Answer - 20 : -
The syntax of a for loop looks as follows : for iterating_var in sequence: statements(s)
Example : for i in range (4):
print i
output : 0 1 2 3