DEV Community

Keerthana M
Keerthana M

Posted on

python

Task1:
sentence = 'Chief Minister Vijay returned from UK'
l = sentence.split(' ')
print(l)
max_length = 0
longest_word = ''
for word in l:
if len(word) > max_length:
max_length = len(word)
longest_word = word
else:
print(longest_word)

Task-2
import sys
sentence = 'Chief Minister Vijay returned from UK'
l = sentence.split(' ')
print(l)
min_length = sys.maxsize
longest_word = ''
for word in l:
if len(word) < min_length:
min_length = len(word)

longest_word = word

for word in l:
if len(word) == min_length:
print(word)

Task-3
sentence = 'today is thursday'

thursday is today

l = sentence.split(' ')
i = len(l) - 1
sentence2 = ''
while i >=0:
sentence2 = sentence2 + l[i] +' '
i-=1
else:
print(sentence2)

Top comments (0)