The longest word sentence
Write a program that receives a sentence from the input andThe longest and the shortestPrint the word in the sentence in the output
Write a program that receives a sentence from the input andThe longest and the shortestPrint the word in the sentence in the output
let msg = 'error' alert(msg)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
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
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)}")
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)
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]}")
Please check before submission. It's wrong
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)}')
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}')
def find_longest_and_shortest_words(sentence): # Divide the sentence into words words = sentence.split() # Check if there is no word if not words: return None, None # Find the longest and shortest word longest_word = max(words, key=len) shortest_word = min(words, key=len) return longest_word, shortest_word def main(): # Receive a sentence from the user sentence = input("لطفاً یک جمله وارد کنید: ") longest_word, shortest_word = find_longest_and_shortest_words(sentence) if longest_word and shortest_word: print(f"طولانیترین کلمه: '{longest_word}'") print(f"کوتاهترین کلمه: '{shortest_word}'") else: print("هیچ کلمهای در جمله وجود ندارد.") if __name__ == "__main__": main()
Submitting answers is currently unavailable.
Write a program that receives 2 numeric value from the input and stores in variables A and B. Then move the values of these two variables (the value of variable A is to be stored within B and the value of variable B is saved within a)
Write a program that receives the age of father and son from the input and prints them (subtraction) in the output
Write a program that receives the user's username and password and checks whether the username and password entered are correct? Username - Passwordamirhossein - 12345hooshang - 009922 ...
Write a program that obtained a person's / BMI body / BMI formula and, according to the information below, shows the status of the person BMI = w / h * h formula = weight divided by second power BMI ...
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.