KnowledgeBoat Logo

Computer Science

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

Python

Python String Manipulation

17 Likes

Answer

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

Answered By

6 Likes


Related Questions