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


testStr = "abcdefghi"

inputStr = input ("Enter integer : ")

inputInt = int(inputStr)

count = 2

newStr = ' '

while count <= inputInt :

    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 (inputInt)#Line 5



(i) Given the input integer 4 what output is produced by Line 2?

(a) abcdefg
(b) aabbccddeeffgg
(c) abcdeefg
(d) ghi
(e) None of these

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

(a) abcdefg
(b) aabbccddeeffgg
(c) abcdeefg
(d) ghi
(e) None of these

(iii) Given the input integer 3, what output is produced by Line 4?

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

(iv) Given the input integer 3, what output is produced by Line 5?

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

(v) Which statement is equivalent to the statement found in Line 1?
(a) testStr = testStr[2:0]
(b) testStr = testStr[2:-1]
(c) testStr = testStr[2:-2]
(d) teststr = teststr - 2
(e) None of these

Answer =

(i) Option (c)
(ii) Option (d)
(iii) Option (e)
(iv) Option (d)
(v) Option (e)

Post a Comment

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

Previous Post Next Post