KnowledgeBoat Logo

Computer Science

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

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

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

Python String Manipulation

3 Likes

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.

Answered By

1 Like


Related Questions