Course Home | Class Schedule | Assignments | Git Submission | Perusall | Python | Tutoring

Saint Louis University

Computer Science 1300/5001
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2018

Computer Science Department

Homework Assignment 11

Functions

Overview

Topic: Functions
Related Reading: Chapter 11
Due: 10:00am, Tuesday 9 October 2018

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


Problems to be Submitted (20 points)

  1. (10 points)

    Write a function threshold(values, goal) that behaves as follows. The first parameter is a sequence of numbers. The second parameter is a single positive number. The function is to return the smallest possible integer n such that the sum of the first n numbers in the sequence is greater than or equal to goal. For example, threshold([5, 3, 8, 2, 9, 1], 17) should return 4 because the goal can be achieved by the sum of the first four values (5+3+8+2).

    If the goal is unachievable, the function should return 0.

  2. (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 slicking 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.


Michael Goldwasser
CSCI 1300/5001, Fall 2018
Last modified: Sunday, 07 October 2018
Course Home | Class Schedule | Assignments | Git Submission | Perusall | Python | Tutoring