# Initialize Otter
import otter
grader = otter.Notebook("hw8-strings.ipynb")

Homework 8#

This assignment includes three problems on the topic of strings.

Entering Your Information for Credit#

To receive credit for assignments it is important we can identify your work from others. To do this we will ask you to enter your information in the following code block.

Before you begin#

Run the block of code at the top of the notebook that imports and sets up the autograder. This will allow you to check your work.

# Please provide your first name, last name, Drexel ID, and Drexel email. Make sure these are provided as strings. "STRINGS ARE TEXT ENCLOSED IN QUOTATION MARKS."

# In the assignments you will see sections of code that you need to fill in that are marked with ... (three dots). Replace the ... with your code.
first_name = ...
last_name = ...
drexel_id = ...
drexel_email = ...
grader.check("q0-Checking-Your-Name")

Question 1: Remove non alpha characters

In this lab you will write a function which takes in a string and removes all of the non-alphabetic characters from it.

Write python code to do the following:

  • Define a function called remove_non_alpha that takes an input string s

  • Loop through each character in the string, adding it to an output string if it is an alphabetic character.

  • Return the final string.

Your code replaces the prompt: ...

...
grader.check("q1-nonalpha")

Question 2: Palindrome Detector

A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: β€œbob,” β€œsees,” or β€œnever odd or even” (ignoring spaces). Write a program whose input is a word or phrase, and that outputs true if the input is a palindrome, otherwise false. In determining if a string is a palindrome, you should treat upper vs. lower case versions of characters as the same letter, and you may ignore all spaces.

Write python code to do the following:

  • Define a function called is_palindrome that takes in one input parameter x.

  • Convert the string x to be all lower case.

  • Remove all spaces from string x. (Hint: use the string.replace method)

  • Loop through the characters of x to determine if it is palindromic

Your code replaces the prompt: ...

...
grader.check("q2-palindrome")

Question 3: Count characters

Your task is to write a function that takes in a character and a string and retruns the count of how many times that character appears in the string.

Write python code to do the following:

  • Define a function called count_characters which takes two arguments, a character c, and a string s

  • Your function should loop through the string and character by character, counting every time the character c is encountered

  • Return the total count, or 0 if the character c is not part of string s

Your code replaces the prompt: ...

...
grader.check("q3-countchars")

Submitting Your Assignment#

To submit your assignment please use the following link the assignment on GitHub classroom.

Use this link to navigate to the assignment on GitHub classroom.

If you need further instructions on submitting your assignment please look at Lab 1.

Viewing your score#

It is your responsibility to ensure that your grade report shows correctly. We can only provide corrections to grades if a grading error is determined. If you do not receive a grade report your grade has not been recorded. It is your responsibility either resubmit the assignment correctly or contact the instructors before the assignment due date.

Each .ipynb file you have uploaded will have a file with the name of your file + Grade_Report.md. You can view this file by clicking on the file name. This will show you the results of the autograder.

We have both public and hidden tests. You will be able to see the score of both tests, but not the specific details of why the test passed or failed.

Note

In python and particularly jupyter notebooks it is common that during testing you run cells in a different order, or run cells and modify them. This can cause there to be local variables needed for your solution that would not be recreated on running your code again from scratch. Your assignment will be graded based on running your code from scratch. This means before you submit your assignment you should restart the kernel and run all cells. You can do this by clicking Kernel and selecting Restart and Run All. If you code does not run as expected after restarting the kernel and running all cells it means you have an error in your code.

Fin#