Q. On what principles does python compare two string? Write a program that takes two strings from the user and displays the smaller string in a single line and largest string as per this format:
1st letter last letter
2nd letter 2nd last letter
3rd letter 3rd last letter
:
You can understand by Watching video :-
Answer :-
str1 = input("Enter first string = ") str2 = input("Enter second string = ") if len(str1) > len(str2) : big,small = str1 , str2 else : big , small = str2 , str1 print("big word ", big) print ("smaller word ", small) length = len(big) step = length // 2 for i in range (step) : for j in range (length) : if j < step : if i == j : print (big [ j ], end ="") else : print ( " " , end = "") else : if j == length -i -1 : print (big [ j ], end = "") else : print (" ", end = "") print () if length % 2 == 1 : for i in range (step): print (" ", end = "") print (big [step])
Output :-
Enter first string = Path
Enter second string = Walla
big word Walla
smaller word Path
W a
a l
l
>>>
Enter first string = Portal
Enter second string = Path
big word Portal
smaller word Path
P l
o a
rt
>>>
Enter first string = Express
Enter second string = Portal
big word Express
smaller word Portal
E s
x s
p e
r
>>>
This is really helpful
ReplyDeleteWelcome : )
Delete: )
ReplyDeleteoh yaaaaaaaaaa
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )