Using python 3.5.2 and IDLE Write a Python program that takes a list of words an
ID: 3803350 • Letter: U
Question
Using python 3.5.2 and IDLE Write a Python program that takes a list of words and reports the following: (write a function to do each of the actions) (5 points) The longest word in the list The shortest word in the list All words that are longer than 7 characters Design and write a Python program that takes a list of integers and returns a proper message if a user-input element appears in the list. Continue to check for input as long as the user wishes. Check to make sure that valid integers have been entered. (5 points)
Explanation / Answer
import sys
def longest(l):
mx = 0
for i in range(1,len(l)):
if(len(l[i])>len(l[mx])):
mx=i
return l[mx]
def smallest(l):
mn = 0
for i in range(1,len(l)):
if(len(l[i])<len(l[mn])):
mn=i
return l[mn]
def more_than_7(l):
ans = []
for i in l:
if(len(i)>7):
ans.append(i)
return ans
kk = sys.stdin.readline()
kk = kk[0:-1]
kk = kk.split()
print(longest(kk))
print(smallest(kk))
print(more_than_7(kk))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.