Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PYTHON - Explain the code with comments for each step (so I can understand the concept). Thanks def word2capitalize (s): TTo take user input
PYTHON - Explain the code with comments for each step (so I can understand the concept). Thanks
def word2capitalize (s): "" TTo take user input and print out that string in the Title Case That is, the first letter of each word is uppercase and the remainder of the word is lowercase. If the entire word is two letters long, the entire word is lower case. The three letter words "and,""the," and "not" are all lowercase while all other three letter wordsare capitalized. The first word in the string is capitalized, no matter how long it is. Test data: input: 'the quick brown dogNow is the time for all good men' And to all a good night' output: 'The Quick Brown Dog Now is the Time For All Good Men'i And to All A Good Night' Params: s (string) Returns: (3 strings) IT skipList= { ' and ' ' ' the ' , ' not ' } sen- s . split ( ' ' ) sentence = ' ' for word in sen: if word not in skipList and len (word) > 2 or len (word) is 1: elif word in skipList and word[0].islower): else: sentence-sentence+''+ word.title () sentence-sentence+''+ word.title () sentence - sentence + ''+ word return sentence.lstrip() s = input ("Type in any string :") sen -word2 capitalize (s) print (sen)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started