Computer Science, asked by tas11, 1 year ago

7. Find the output if the input string is 'Tesť.
(a) S =input("Enter String : ")Test
RS = ""
for ch in S:
RS = ch + RS
print(S + RS)

(b) S = input("Enter string : ")
RS = " "
for ch in S :
RS = ch + 2 + RS
print(RS + S)​

Answers

Answered by poojan
20

Answer:

(a) testtesttesttesttest

(b) error

Explanation:

(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.


AbhijithPrakash: Wondrous answer!!
Similar questions