CPSC120A
Fundamentals of Computer Science I

Post-lab 16

Strings

In this post lab, you will demonstrate your knowledge of strings by writing a simple function to create a copy of a segment of a given string.

Details

Create a function called string_slice(input_string, start_index, end_index) in a filed called slicing.py. This function takes a string and two positive integers as parameters. The function should return a copy of the characters from input_string between the specified start and end indicies. Assume that the start index is less than or equal to the end index. The return value should not include the character at the end_index. The function must use a for loop to traverse the input string and an accumulator to create the return value.

Make sure you have sufficient test cases and that you follow all of the course's coding conventions.

Sample Test Cases

Function Parameters Expected Output
'Hello', 0, 2 'He'
'Hello', 1, 3 'el'
'Hello', 2, 4 'll'

Submission

Submit your program as a .py file on the course Inquire page before class on Wednesday October 8th.