CBSE Class 11 Computer Science Question 66 of 91

String Manipulation — Question 11

Back to all questions
11
Question

Question 5

Carefully go through the code given below and answer the questions based on it :

inputStr = input(" Give me a string:")
biglnt = 0
littlelnt = 0
otherlnt = 0
for ele in inputStr:
    if ele >= 'a' and ele <= 'm':     # Line 1
        littlelnt = littlelnt + 1
    elif ele > 'm' and ele <= 'z':
        biglnt = biglnt + 1
    else:
        otherlnt = otherlnt + 1
print (biglnt)             # Line 2
print (littlelnt)          # Line 3
print (otherlnt)           # Line 4
print (inputStr.isdigit()) # Line 5

(i) Given the input abcd what output is produced by Line 2?

  1. 0
  2. 1
  3. 2
  4. 3
  5. 4

Answer

Option 1 — 0

Explanation

In the input abcd, all the letters are between a and m so the condition — if ele >= 'a' and ele <= 'm' is always true. Hence, biglnt is 0.

(ii) Given the input Hi Mom what output is produced by Line 3?

  1. 0
  2. 1
  3. 2
  4. 3
  5. None of these

Answer

Option 3 — 2

Explanation

In the input Hi Mom, only two letters i and m satisfy the condition — if ele >= 'a' and ele <= 'm'. Hence, value of littlelnt is 2.

(iii) Given the input Hi Mom what output is produced by Line 4?

  1. 0
  2. 1
  3. 2
  4. 3
  5. None of these

Answer

Option 4 — 3

Explanation

In the input Hi Mom, 3 characters H, M and space are not between a and z. So for these 3 characters the statement in else part — otherlnt = otherlnt + 1 is executed. Hence, value of otherlnt is 3.

(iv) Given the input 1+2 =3 what output is produced by Line 5?

  1. 0
  2. 1
  3. True
  4. False
  5. None of these

Answer

Option 4 — False

Explanation

As all characters in the input string 1+2 =3 are not digits hence isdigit() returns False.

(v) Give the input Hi Mom, what changes result from modifying Line 1 from

if ele >= 'a' and ele <='m' to the expression
if ele >= 'a' and ele < 'm'?

  1. No change
  2. otherlnt would be larger
  3. littlelnt would be larger
  4. biglnt would be larger
  5. None of these

Answer

Option 2 — otherlnt would be larger

Explanation

For letter m, now else case will be executed increasing the value of otherlnt.

Answer