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 abcd what output is produced by Line 2?

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

Python String Manipulation

3 Likes

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.

Answered By

2 Likes


Related Questions