Programming

MATH 230 : Fall 2023

Department of Mathematics - SUNY Geneseo
⇐ Back

Homework 8 - More with Strings

Due Date: November 14, 2023

Upload

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

  1. In the Python console, define the following string:
    >>> famous_quote = "Sometimes life hits you in the head with a brick. Don't lose faith. - Steve Jobs"
    In the Python console, type famous_quote. and then press the TAB key (note the period after quote). 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 to famous_quote. Hint: You may find the following site useful: Strings in Python
  2. The string method split is one of the most useful string methods. For each string below, split the string using the specified delimiter.
    1. 585-554-8090 : delimiter is a single dash (-)
    2. The sun will come up tomorrow! : delimiter is a single blank space character
    3. papayas, aguacates, mangos, platanos : delimiter is a single comma (,)
    4. What happens when you use the split method with no delimiter parameter?
  3. Another important string method is join. Provide three examples that demonstrate the typical uses of the join method.
  4. Yet another important string method is strip. Provide three examples that demonstrate the typical uses of the strip method.
  5. 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
    See you later alligator
    then the return value of your function should be
    SeE YoU LateR AlligatoR
    Single letter words should be returned in upper case.
  6. 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.