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

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

Python String Manipulation

1 Like

Answer

Option 2 — otherlnt would be larger

Explanation

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

Answered By

2 Likes


Related Questions