CMSC 201

# Homework 5 - Due 3/12

This homework must be submitted by 8pm on the due date to get any credit.

In this homework, you will be creating different functions! For each assignment, you will create a single function. It will live in the file hw5.py. Here is a template. You may write more functions than we give you, but you must create the ones listed below. You should not call input() anywhere in this assignment.

Furthermore, you may not use the following functions anywhere in the assignment:

1. list.reverse()
2. list.sort()
3. string.count()
4. list.count()
In general, you should be using the basic list operations we taught you in class--things like append(), remove(), etc. If you come across a string or list function that makes the problem trivial, don't use it!

For this assignment, the coding standards have changed slighy in order to simplify them. The class coding standards are here

1. letterCount(letter, myString) This function should take a single letter, and then a string. It should return the number of times letter occurs in myString. So the call letterCount('h', 'hello') should return 1, and the call letterCount('a', 'aardvark') should return 3. This should be case sensitive-- letterCount('H', 'hello') should return 0.
2. sortList(myList) This function should take myList and return myList sorted. If you are struggling with this, use your code from part 4 of the last homework. If you already have code that puts a number into an already sorted list, with an extra loop sorting shouldn't be that hard. So calling sortList([4, 5, 3, 1]) should return [1, 3, 4, 5], and sortList([8, 10, 1, 2]) should return [1, 2, 8, 10]. If you call .sort() you will get exactly zero points for this section.
3. isPalindrome(myString) Returns True if myString is a palindrome (the same forward as it is backward) and False otherwise. myString will be a single, lowercase word word. For example, isPalindrome("tacocat") should return True, isPalindrome("anna") should return True, and isPalindrome("DanTheMan") should return False.
4. main() Main should be used by you to test your program. The main you should submit should show 3 to 4 examples of your function working. So for the isPalindrome, you could print out the result of calling isPalindrome on each of the three strings we gave you in the example, along with one or two examples in which your function works. main() does not need to do things in any particular order or format. Simply call each function 3 or 4 times with different input and print the output. We will be looking at it by hand to make sure you tested your programs.

# Submitting

When you've finished your homework, use the submit command to submit the file. You must be logged into your account and you must be in the same directory as the file you're trying to submit. At the Linux prompt, type

submit cs201 HW5 hw5.py

After entering the submit command shown above, you should get a confirmation that submit worked correctly:

Submitting hw5.py...OK

If not, check your spelling and that you have included each of the required parts and try again.

You can check your submission by entering:

submitls cs201 HW5

You should see the name of the file that you just submitted, in this case hw5.py

 Adapted from UMBC CSHC's webpage design