KnowledgeBoat Logo

Computer Science

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

in1Str = input(" Enter string of digits: ")
in2Str = input(" Enter string of digits: ")

if len(in1Str)>len(in2Str):
    small = in2Str
    large = in1Str
else:
    small = in1Str
    large = in2Str
newStr = ''
for element in small:
    result = int(element) + int(large[0])
    newStr = newStr + str(result)
    large = large[1:]
print (len(newStr))      # Line 1
print (newStr)           # Line 2
print (large)            # Line 3
print (small)            # Line 4

Given a first input of 123 and a second input of 4567, what result is produced by Line 4?

  1. 123
  2. 4567
  3. 7
  4. 3
  5. None of these

Python String Manipulation

1 Like

Answer

Option 1 — 123

Explanation

As length of 123 is less than length of 4567 so 123 is assigned to variable small and gets printed in line 4.

Answered By

2 Likes


Related Questions