Computer Science
Carefully go through the code given below and answer the questions based on it :
theStr = " This is a test "
inputStr = input(" Enter integer: ")
inputlnt = int(inputStr)
testStr = theStr
while inputlnt >= 0 :
testStr = testStr[1:-1]
inputlnt = inputlnt - 1
testBool = 't' in testStr
print (theStr) # Line 1
print (testStr) # Line 2
print (inputlnt) # Line 3
print (testBool) # Line 4
Given the input integer 2, what output is produced by Line 3?
- 0
- 1
- 2
- 3
- None of these
Python String Manipulation
3 Likes
Answer
Option 5 — None of these
Explanation
Value of inputlnt will be -1 as till inputlnt >= 0 the while loop will continue executing.
Answered By
3 Likes
Related Questions
Carefully go through the code given below and answer the questions based on it :
theStr = " This is a test " inputStr = input(" Enter integer: ") inputlnt = int(inputStr) testStr = theStr while inputlnt >= 0 : testStr = testStr[1:-1] inputlnt = inputlnt - 1 testBool = 't' in testStr print (theStr) # Line 1 print (testStr) # Line 2 print (inputlnt) # Line 3 print (testBool) # Line 4
Given the input integer 3, what output is produced by Line 1?
- This is a test
- This is a
- is a test
- is a
- None of these
Carefully go through the code given below and answer the questions based on it :
theStr = " This is a test " inputStr = input(" Enter integer: ") inputlnt = int(inputStr) testStr = theStr while inputlnt >= 0 : testStr = testStr[1:-1] inputlnt = inputlnt - 1 testBool = 't' in testStr print (theStr) # Line 1 print (testStr) # Line 2 print (inputlnt) # Line 3 print (testBool) # Line 4
Given the input integer 3, what output is produced by Line 2?
- This is a test
- s is a t
- is a test
- is a
- None of these
Carefully go through the code given below and answer the questions based on it :
theStr = " This is a test " inputStr = input(" Enter integer: ") inputlnt = int(inputStr) testStr = theStr while inputlnt >= 0 : testStr = testStr[1:-1] inputlnt = inputlnt - 1 testBool = 't' in testStr print (theStr) # Line 1 print (testStr) # Line 2 print (inputlnt) # Line 3 print (testBool) # Line 4
Given the input integer 2, what output is produced by Line 4?
- False
- True
- 0
- 1
- None of these
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 4, what output is produced by Line 2?
- abcdefg
- aabbccddeeffgg
- abcdeefgh
- ghi
- None of these