String - First and Last Pattern
The program must accept a string 5 as the input. The program must print the characters of the string based on the following conditions
in the 1 line the first and the last characters of the string S must be printed. -In the 2nd line, the first two and the last two characters of the string S must be printed in reverse ore
-In the 3 line the first three and the last three characters of the string S must be printed in reverse Similarly, the program must print the remaining lines as the output.
Boundary Condition(s):
2 <= Length of S <= 100
Input Format:
The first line contains
Output Format:
The first Llines each contains the characters of the string S based on the given conditions.
Example Input/Output 1:
Input
orange
Output
toeg
aregn naroegna
gnaroegnar egnaroegnato
Explanation
Here the length of the string orange is 6. So the pattern contains 6 lines.
De 1 and 6 characters)
ro eg (first 2 and last 2 characters in reverse order aro egn (first 3 and last 3 characters in reverse order)
naro egna (first 4 and last 4 characters in reverse order) gnaro egnar (first 5 and last 5 characters in reverse order) egnaro (first 6 and last 6 characters in reverse orden
PYTHON CODE:
#type in single line
(lambda s:print(*list(map(lambda x:s[:x][::-1]+s[-x:][::-1],
list(range(1,len(s)+1)))),sep="\n"))(input().strip())
Post a Comment