CBSE Class 11 Computer Science
Question 85 of 91
String Manipulation — Question 9
Back to all questions 9
Question Question 9
Write a program that takes two strings from the user and displays the smaller string in single line and the larger string as per this format :
1st letter last letter
2nd letter 2nd last letter
3rd letter 3rd last letter
For example,
if the two strings entered are Python and PANDA then the output of the program should be :
PANDA
P n
y o
t h
Solution
str1 = input("Enter first string: ")
str2 = input("Enter second string: ")
small = str1
large = str2
if len(str1) > len(str2) :
large = str1
small = str2
print(small)
lenLarge = len(large)
for i in range(lenLarge // 2) :
print(' ' * i, large[i], ' ' * (lenLarge - 2 * i), large[lenLarge - i - 1], sep='')Output
Enter first string: Python
Enter second string: PANDA
PANDA
P n
y o
t h