Anjeev Singh Academy

Anjeev Singh Academy

Class 11 Computer Science Ch 9 Flow of Control Check Point 9.2 Sumita Arora Solution

Class 11 Computer Science 083

Ch 9: Flow of Control

Check Point 9.2

Sumita Arora Book Exercise Solution

Que 1. What is a Selection Statement? Which selection statement does Python provide?

Answer: Selection statement which allows executing the set of statement on the basis of condition i.e. it selects the statement for execution when the condition is true and another set of statements when the condition is false.

Types of Selection Statement in Python:

(a) if
(b) if – else
(c) if – elif – else
(d) Nested if else

Que 2. How does a conditional expression affect the result of an if statement?

Answer: In Python, if the statement has a conditional expression, which decides the execution of the statement. If the conditional expression is True then it executes the set of statements followed by if otherwise, it executes the set of statements followed by else.

Que 3. Correct the following code fragment:-

if (x = 1)
   k = 100
else
   k = 10

Answer: Corrected code:

if (x = = 1 ) :    # using == and colon 
   k = 100
else :               # missing of colon
   k = 10

Que 4. What will be the output of the following code fragment if the input given is (i) 7 (ii) 5 ?

a = input("Enter a number")
if ( a == 5 ) :
   print("Five")
else :               
   print("Not Five")

Answer: (i) When the input is 7, then the output is Not Five

Explanation: As we know input() function takes the input and returns the value as a string, So when you input 7 then the value of a is ‘7’ (i.e. not a number, it is a string), and the condition a == 5 becomes False, so it executes the body of the else statement.

(ii) When the input is 5, then the output is Not Five

Explanation: As we know input() function takes the input and returns the value as a string, So when you input 5 then the value of a is ‘5’ (i.e. not a number, it is a string), and the condition a == 5 becomes False, so it executes the body of the else statement.

Que 5. What will be the output of the following code fragment if the input given is (i) 2000 (ii) 1900 (iii) 1971 ?

a = int(input("Enter a 4 digit year "))
if ( year % 100 == 0 ) :
   if (year % 400 == 0 ):
        print("LEAP century year")
else :               
   print("Not century year")

Answer: (i) When the input of the year is 2000, then the output is LEAP century year

Explanation: When you input 2000 then the value of the year is 2000, int() function converts the string ‘2000’ value into the integer value.

The first condition year % 100 == 0 becomes True, then it checks the nested condition year % 400 == 0, and it also gives a True value,

then finally it executes the body of the nested if statement.

(ii) When the input of the year is 1900, then No output will come.

Explanation: When you input 1900 then the value of the year is 1900, int() function converts the string ‘1900’ value into the integer value.

The first condition year % 100 == 0 becomes True, then it checks the nested condition year % 400 == 0, and it gives a False value.

Because in the given code there is no else statement for nested if, so the code does not give any output.

(iii) When the input of the year is 1971, then the output is Not century year.

Explanation: When you input 1971 then the value of the year is 1971, int() function converts the string ‘1971’ value into the integer value.

The first condition year % 100 == 0 becomes False, then it executes the body of else which is given in the code.

Que 6. What will be the output of the following code fragment if the input given is (i) 2000 (ii) 1900 (iii) 1971 ?

a = int(input("Enter a 4 digit year "))
if ( year % 100 == 0 ) :
   if (year % 400 == 0 ):
        print("LEAP century year")
   else :               
        print("Not century year")

Answer: (i) When the input of the year is 2000, then the output is LEAP century year

Explanation: When you input 2000 then the value of the year is 2000, int() function converts the string ‘2000’ value into the integer value.

The first condition year % 100 == 0 becomes True, then it checks the nested condition year % 400 == 0, and it also gives a True value,

then finally it executes the body of the nested if statement.

(ii) When the input of the year is 1900, then the output is Not century year.

Explanation: When you input 1900 then the value of the year is 1900, int() function converts the string ‘1900’ value into the integer value.

The first condition year % 100 == 0 becomes True, then it checks the nested condition year % 400 == 0, and it gives a False value, then it executes the body of the else statement of the nested if.

(iii) When the input of the year is 1971, then No output will come.

Explanation: When you input 1971 then the value of the year is 1971, int() function converts the string ‘1971’ value into the integer value.

The first condition year % 100 == 0 becomes False, and in the given code no else statement is written for the first if statement. That’s why it does not give any output.

Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Scroll to Top