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

theStr = 'This is a test '
inputStr = input ("Enter integer: ")
inputInt = int (inputStr)
testStr = theStr
while inputInt >= 0 :
    testStr = testStr[1:-1]
    inputInt = inputInt - 1

testBool = 't' in testStr
print (theStr)# Line 1
print (testStr)# Line 2
print (inputInt)# Line 3
print (testBool)# Line 4
(i) Given the input integer 3, what output is produced by Line 1?

(a) This is a test
(b) This is a
(c) is a test
(d) is a
(e) None of these

(ii) Given the input integer 3, what output is produced by Line 2?

(a) This is a test
(b) This is a
(c) is a test
(d) is a
(e) None of these

(iii) Given the input integer 2. What output is produced by Line 3?

(a) 0
(b) 1
(c) 2
(d) 3
(e) None of these

(iv) Given the input integer 2. What output is produced by Line 4?

(a) False
(b) True
(c) 0
(d) 1
(e) None of these


Answer :-


(i) Option (a) This is a test 

(ii) Option (e)  is a t

(iii) Option (e) -1

(iv) Option (b) True


9 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. I think first answer is option d

    ReplyDelete
  2. i think second question has answer D and third one has answer A

    ReplyDelete
    Replies
    1. All are correct Please check it again in your IDLE Python.

      Delete
  3. (ii) will be option (b) s is a t
    Thank you ✨

    ReplyDelete
    Replies
    1. Welcome : ) , you can run code in IDLE Python.

      Delete
  4. I thik (iii) is wrong the answer (e) is none of these

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post