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 3?

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

Python String Manipulation

2 Likes

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.

Answered By

1 Like


Related Questions