473,703 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write a python program that splits a sentence into words

1 New Member
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 21634
dev7060
644 Recognized Expert Contributor
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 Contributor
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 New Member
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.
Mar 17 '23 #4
Roman123456789
3 New Member
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.
Mar 29 '23 #5

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

Similar topics

2
20497
by: Peter McKeown | last post by:
I want to write letters to people in my database. I have a field Surname and a field FirstNames. How do I get the first letters of each word in FirstNames? For example: Surname "Bloggs" FirstNames "John Henry" I want to addres a letter to "J H Bloggs"
2
3503
by: pchahar | last post by:
Write a program to process a text file. The program will determine how many unique words there are in the text file that begin with each letter of the alphabet. The text file name will be given as a command line argument to the program. You will use an array of pointers to implement this program. There will be one pointer for each letter of the alphabet. The array will be indexed by each letter. To do so, subtract the ASCII value for ‘a’...
2
1334
by: balck05 | last post by:
I need to write a program that will total the integer values of each characters in a string not including spaces. The program should produce two totals. First should be a fixed string, second should using an empty string of 80 charact. max lenght, using both alphanumeric and numeric characters. I'am fresh in this so please help me. The code: using System; using System.Collections.Generic; using System.Text; class Program
5
1593
by: balck05 | last post by:
I need to write a program that will total the integer values of each characters in a string not including spaces. The program should produce two totals. First should be a fixed string, second should using an empty string of 80 charact. max lenght, using both alphanumeric and numeric characters. I'am fresh in this so please help me. Can you give me any clue!? using System; using System.Collections.Generic; using System.Text; class...
1
4350
by: fellya | last post by:
Hi, i don't have enough experience in writing codes in Python but now i'm trying to see how i can start using Python. I've tried to write a simple program that can display a sentence. now my problem is how to write a code using split function to split that sentence into words then print out each word separately. let me give u an example: >>>sentence=" My question is to know how to write a code in Python" then the output of this...
5
5029
by: Russell Melmed | last post by:
I have been struggling with this one for some time now in Access 2003, so I'm reaching out for answers. I am trying to auto-populate an ID field in my form using the first character in each word of a text field, along with the month, day, and year from a date field. I can get the date in there using the Month, Day, and Year functions, and the first character of the first word using the Left function, but have been unsuccessful thus far pulling...
1
1310
by: Keletso | last post by:
How to write a program that reads a line of text, changes each letter to the lowercase, and place in a queue and onto a stack. The program should then verify whether the line of text is palindrome.
0
8667
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9251
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9014
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4429
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2063
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.