CodeSolved

Solved Programming Questions & Exercises

The longest word sentence

Practice Easy 28/ Download 1613 Views

Write a program that receives a sentence from the input andThe longest and the shortestPrint the word in the sentence in the output

13 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
def l_s(matn):
    w=matn.split()
    l_w=max(w, key=len)
    s_w=min(w, key=len)
    return l_w, s_w
matn=input("matn: ")
l,s=l_s(matn)
print(f"long: {l}")
print(f"short: {s}")
jomle = input ("Enter your sentences:")
kalame = jomle.split(" ")
len_kalame = list(map(lambda x: len(x), kalame))
print (f"the longest {max(len_kalame)} and the shortest is {min(len_kalame)}")
H.rezaei Download Python
class Word:
    def __init__(self, word):
        self.word = word
    
    def Print(self):
        words_list = self.word.split()
        longest_word = max(words_list, key=len)
        shortest_word = min(words_list, key=len)
        return words_list, longest_word, shortest_word

words = input("enter your words: ")
obj = Word(words)

words_list, longest_word, shortest_word = obj.Print()
print("کلمات:", words_list)
print("بلندترین کلمه:", longest_word)
print("کوتاه‌ترین کلمه:", shortest_word)
Roghaye.m Download Python
user_input = input("Please enter a text: ")

str_lst = user_input.split(" ")
str_lst.sort()

print(f"Longest word => {str_lst[-1]}")
print(f"Shortest word => {str_lst[0]}")
Behcoder Download Python

Please check before submission. It's wrong Alvandsina


x = input('please enter your sentense:')
x = x.split(' ')
print(f'longest word is : {max(x, key = len)}')
print(f'shortest word is : {min(x, key = len)}')
Alvandsina Download Python
def longest_and_shortest_word(sentence):
    words = sentence.split()
    longest = max(words, key=len)
    shortest = min(words, key=len)
    return longest, shortest

sentence = input("Enter a sentence: ")
longest, shortest = longest_and_shortest_word(sentence)
print("Longest word:", longest)
print("Shortest word:", shortest)
Ai Download Python
sen = input ('Enter a sentence: ')
list_sen = sen.split ()

minimum = list_sen [0]
maximum = list_sen [0]

for word in list_sen:
    if len (word) < len (minimum):
        minimum = word
    if len (word) > len (maximum):
        maximum = word

print (f'Minimum word is: {minimum}')
print (f'Maximum word is: {maximum}')
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close