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'.





Expert's answer

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) )
LATEST TUTORIALS
APPROVED BY CLIENTS