472,146 Members | 1,291 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

Write a python program that splits a sentence into words

Hi
I don't have much experience on python coding. Can someone give me a answer for this ques.
Question: Write a python program that splits a sentence into words. Change the first and last letter of each word into uppercase and display them.
For example if we type input as hello,world
The output must be:
HellO
WorlD
Oct 19 '21 #1
4 10042
dev7060
624 Expert 512MB
Hi
I don't have much experience on python coding. Can someone give me a answer for this ques.
Question: Write a python program that splits a sentence into words. Change the first and last letter of each word into uppercase and display them.
For example if we type input as hello,world
The output must be:
HellO
WorlD
What have you done so far?
Oct 19 '21 #2
SioSio
272 256MB
Expand|Select|Wrap|Line Numbers
  1. import re
  2. txt = 'hello,world hello/world hello+world hello-world'
  3. new_word = []
  4. for word in re.split('[ ,+-/]',txt):
  5.     new_word = word[0].upper() + word[1:len(word)-1] + word[len(word)-1].upper()
  6.     print (new_word)
Oct 21 '21 #3
Vanisha
25 16bit
Here's a simple Python program that uses the split() method to split a sentence into words:
sentence = input("Enter a sentence: ")

words = sentence.split()

print("The words in the sentence are:")
for word in words:
print(word)
If you're looking to improve your coding skills or learn new technologies, join Cetpa Infotech.
Check out our website for more information.
2 Weeks Ago #4
Roman123456789
3 2Bits
why don't you contact Pytnon developers right away? I value my time and I will leave such small tasks for https://lomray.com/. At the same time, you will gain experience on how you could solve this problem.
3 Days Ago #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Peter McKeown | last post: by
5 posts views Thread by balck05 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.