Homework 8 - More with Strings
Due Date: November 14, 2023
Assignments are due by 11:59 pm on the due date. Recall that in almost all cases, your functions should return values and not print them.
Problems
- In the Python console, define the following string:
In the Python console, type>>> famous_quote = "Sometimes life hits you in the head with a brick. Don't lose faith. - Steve Jobs"
famous_quote.
and then press the TAB key (note the period afterquote
). You should see a list of methods that can be applied to a string. What are six of the methods? Then, choose four methods, describe what they do, and apply them tofamous_quote
. Hint: You may find the following site useful: Strings in Python - The string method
split
is one of the most useful string methods. For each string below, split the string using the specified delimiter.585-554-8090
: delimiter is a single dash (-
)The sun will come up tomorrow!
: delimiter is a single blank space characterpapayas, aguacates, mangos, platanos
: delimiter is a single comma (,
)- What happens when you use the
split
method with no delimiter parameter?
- Another important string method is
join
. Provide three examples that demonstrate the typical uses of thejoin
method. - Yet another important string method is
strip
. Provide three examples that demonstrate the typical uses of thestrip
method. - Write a function that will convert the first and last letter of every word in a string to upper case. The function's parameter will therefore be a string and the return value will also be a string. For example, if the input parameter string is
then the return value of your function should beSee you later alligator
Single letter words should be returned in upper case.SeE YoU LateR AlligatoR
- Watch the video on the temperature data. Write code to compute the average of the temperatures from 1895 to 2020. Visit the NOAA website to obtain the data for this problem.