A program which accepts a sentence from a user, and uses a 'for loop' and determines the longest word in the sentence entered.
Print the longest word in a sentence
# 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)
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.