Course Home | Homework | Lab Hours | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science 150
Introduction to Computer Science

Michael Goldwasser

Fall 2005

Dept. of Math & Computer Science

Homework Assignment 03

Using list and str objects

Contents:


Overview

Topic: Using list and str objects
Related Reading: Notes from class, and Chapter 4 of Zelle.
Due: 1:10pm, Monday 19 September 2005

Please make sure you adhere to the policies on academic integrity.


Problems to be Submitted (20 points)

  1. (4 points)

    Given a string, declared as:

    school = 'Saint Louis University'
    
    What command, or series of commands, would allow you to print out the substring 'Louis' based on use of the original string in this specific example?

  2. (4 points)

    Assume that we have a list, initialized as:

    fruits = ['apple','banana','cherry','grape','lime','orange','strawberry']
    
    What command, or sequence of commands, could you use to alter that list, replacing the occurrence of 'lime' with, in the same place, the string 'kiwi'?

  3. (4 points)

    Assume that we have a list, fruits, which contains strings representing the names of various fruits. What command, or sequence of commands, could you use to produce a single string diet which would contains all of the fruits from the list, in order, and separated by a comma and a space.

    As an example, if the list of fruits happened to be

    fruit = ['apple','banana','cherry','grape','lime','orange','strawberry']
    
    the resulting diet should have value:
    'apple, banana, cherry, grape, lime, orange, strawberry'
    
    However, your answer should not be designed solely for this one example.

  4. (4 points)

    Assume that person is a reference to a string of the general form 'firstName lastName'. Give a command, or series of commands, which results in the creation of the corresponding string, 'lastName,  firstName'

  5. (4 points)

    Assume that person is a reference to a string of the form 'firstName middleName lastName'. Give a command, or series of commands, which results in the creation of the corresponding string, 'firstName middleInitiallastName'.

    For example if person = 'Elmer Joseph Fudd', the result should be 'Elmer J. Fudd'.


Extra Credit

  1. (2 points)

    TBA


Michael Goldwasser
CSCI 150, Fall 2005
Last modified: Wednesday, 14 September 2005
Course Home | Homework | Lab Hours | Programming | Schedule & Lecture Notes | Submit