Answer to Question #307804 in Python for jamil

Question #307804

2. Write a Python program to find the largest and smallest word in a string. 

[you are not allowed to use max() and min()]

Sample Input

It is a string with the smallest and largest word. 

Sample Output

The largest word is “smallest” and the smallest word is 'a'.





1
Expert's answer
2022-03-08T13:07:03-0500
input1 = input ('Enter string here')
min = input1.split(' ')[0]
for i in input1.split(' '):
    if len(i) <= len(min):
        min = i
max = input1.split(' ')[0]
for i in input1.split(' '):
    if len(i) >= len(max):
        max = i
print('The biggest word is {} and the smallest word is {}'.format(max, min) )

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS