0

A program which accepts a sentence from a user, and uses a 'for loop' and determines the longest word in the sentence entered.

# Accept a sentence
str=raw_input("Enter a sentence: ")

# Split the sentence at each space
split_str=str.split()

p=0
s=""

for item in split_str:
    if(len(item)>p):
        s=item
        p=len(item)

print("Longest word: "+s)
1
Contributor
0
Replies
1
Views
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.