Course Home | Assignments | Computing Resources | Lab Hours/Tutoring | Python | Schedule | Submit

Saint Louis University

Computer Science 1300
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2017

Computer Science Department

Homework Assignment 05

While Loops and Functions

Contents:


Overview

Topic: While Loops, Functions
Related Reading: Chapter 5.1-5.3
Due: 11:00am, Wednesday, 4 October 2017

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


Problems to be Submitted (18 points)

  1. (4 points)

    Exercise 5.9 on page 196 of the book.

  2. (4 points)

    Write a function acronym(phrase) that accepts a string as a parameter, and returns a new string that includes the first letter of every word in the original phrase, all in uppercase. For example, a call to acronym('Laughing out loud') should return the string 'LOL'.

    Note well: your task here is to return the string to the caller. There should be no user interactions from this function.

  3. (10 points)

    Strings have many convenient behaviors, one of which is that you can test whether a pattern occurs in another string, using the syntax

    pattern in original
    which produces a boolean result.

    We want you to implement this test from basic principles. Provide an implemenation of a function with calling signature

    isSubstring(pattern, original)
    that returns True or False, depending on the given parameters. Furthermore, you must not rely on any of the built-in behaviors of the string class, other than the fact that you can determine their lengths and you can use indexing to retrieve a single character of a string at a given index. That is, you are allowed to use syntaxes such as len(original) or pattern[j], but you must not use any other features of the string class such as find, index, or slicing notation pattern[j:k]. Instead use control structures to look for the pattern yourself, presumably testing every possible placement of where it might occur within the original string, and then testing character-by-character to see if you find a match.


Extra Credit

  1. (2 points)

    Exercise 5.25 on page 199 of the book.


Michael Goldwasser
CSCI 1300, Fall 2017
Last modified: Sunday, 07 October 2018
Course Home | Assignments | Computing Resources | Lab Hours/Tutoring | Python | Schedule | Submit