-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp38.py
More file actions
32 lines (23 loc) · 833 Bytes
/
p38.py
File metadata and controls
32 lines (23 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# p38.py
# Rishi Saravanan
# Python 3.11.9
# Description:
'''
Write a program that asks the user to enter a sentence.
The program then finds the longest word in the sentence, and shows it.
Note: The use of python functions max() and sorted() is not permitted!
'''
sentence = input("Please enter a sentence: ")
sentenceSplit = sentence.split(" ")
longest = sentenceSplit[0]
for i in range(1,len(sentenceSplit),1):
if len(sentenceSplit[i]) > len(longest):
longest = sentenceSplit[i]
print('The longest word is', longest)
print(longest, 'has', len(longest), 'characters')
'''
==== RESTART: C:/Users/rishi/AppData/Local/Programs/Python/Python311/p34.py ====
Please enter a sentence: what are you doing tomorrow hello
The longest word is tomorrow
tomorrow has 8 characters
'''