Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! This is coding in Python, thank you! 4. Write a function called add_spaces that takes a string called my_str as a parameter, the

Please help! This is coding in Python, thank you!

4. Write a function called add_spaces that takes a string called my_str as a parameter, the string represents a sentence in which all of the words are run together but the first character of each word is uppercase. The function returns a new string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example the string StopAndSmellTheRoses. would be converted to Stop and smell the roses..

Save the function in a PyDev library module named a8_functions.py def add_spaces(my_str):

"""

-------------------------------------------------------

create a new string with added space between words

new_str = add_spaces (my_str)

------------------------------------------------------- pre-condition: my_str: string that represents a sentence in which all the words are run together (no spaces), but the first character of each word is uppercase. my_str should has at least one character (str) post-conditions: returns new_str: new string in which the words are separated

by spaces and only the first word starts with an uppercase character. -

------------------------------------------------------

"""

Write a program q4.py to test your function. Your program accepts as input a sentence from the user with no spaces in it, calls your function and displays the converted string with the added spaces. test your program with a string other than the one given in the examples. 5. A word chain is a list of words such that for each consecutive pair of words, the last letter in the first word is the same as the first letter in the second word. For example, the following list of animals forms a word chain: 'camel', 'leopard', 'dog', 'giraffe', 'elephant'. Write a function is_word_chain that takes a list of words(list of strings) called my_list as parameter and returns True if the list contains a word chain and False otherwise. Your list should have at least 2 words. Write a program q5.py to test your function.

Test your program with two lists of string, where one list represents a word chain and the other is not.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Question What happens to my plan if I die?

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago