Computer Science

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

testStr = "abcdefghi"                    
inputStr = input ("Enter integer:")      
inputlnt = int(inputStr)                 
count = 2                                
newStr = ''                               
while count <= inputlnt :                
    newStr = newStr + testStr[0 : count]
    testStr = testStr[2:]      #Line 1   
    count = count + 1                    
print (newStr)                 # Line 2
print (testStr)                # Line 3  
print (count)                  # Line 4  
print (inputlnt)               # Line 5  

Given the input integer 3, 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 5 — None of these

Explanation

Looking at the condition of while loop — while count <= inputlnt, the while loop will stop executing when count becomes greater than inputlnt. Value of inputlnt is 3 so when loop stops executing count will be 4.

Answered By

1 Like


Related Questions