InterviewSolution
Saved Bookmarks
| 1. |
7. Find the output if the input string is 'Tesť. (a) S =input("Enter String : ")TestRS = ""for ch in S:RS = ch + RSprint(S + RS)(b) S = input("Enter string : ")RS = " "for ch in S :RS = ch + 2 + RSprint(RS + S) |
|
Answer» (a) testtesttesttesttest(b) errorExplanation:(a)In a, as the length of the STRING 'test' is 4, the loop runs 4 TIMES concatinating 'test' for 4 times to ch. (one per each iteration)So, totally, at the end, rs which contains 4 'test' is CONCATENATED to s which contains a 'test'.So, the final output is testtesttesttesttest(b)In the statement RS=ch+2+RS, we GET an error as 2 is an INTEGER and ch, RS are strings.We can never concatenate an integer and a string.So, an error occurs. |
|