Write a python program to pass a string to the function .Return and display the longest word
def longest_word(n):
n1=""
for i in n.split():
if len(i)>len(n1):
n1=i
print("longest word ",n1)
def main():
#n=input("Enter any string ")
n="Hello how are you greeting you"
print("String is ",n)
longest_word(n)
"""
if __name__=='__main__':
main()
"""
#or
#function calling
main()
Output:-
(1). String is Hello how are you greeting you
longest word greeting
(2).If n=”Nice to meet you” then,
String is Nice to meet you
longest word Nice
No comments:
Post a Comment