Skip to content

Latest commit

 

History

History
42 lines (26 loc) · 2.87 KB

File metadata and controls

42 lines (26 loc) · 2.87 KB

Assignment 3 - Strings and Awesome animals

Python strings reading and practice

Read the W3 strings section and work through the exercises.

Awesome animals exercise

NOTE: For this assignment, you are not allowed to use built-in modules such as csv or third-party libraries such as pandas.

This coding assignment will require you to apply the skills we've learned in the course of our earlier Python readings and the following tutorials:

It will also require you to learn on your own about a few features of working with Python strings (see below for more details).

To complete the coding exercise, read and follow the instructions below:

  • On the command line, use DataKit to create a new project called comm-177p-assignment-3. Remember, all you should need is datakit project create if your system is set up correctly. Points will be deducted if the project is not named correctly!
  • Create a python script called filter_awesome_animals.py in the project's scripts/ folder.
  • Inside the script, read the data from animal_ratings.csv. You do not have to programmatically fetch this data in the script since we haven't covered how to do this yet. Instead, manually download a copy of the file and save it alongside the filter_awesome_animals.py in the scripts/ directory.
  • In the script, filter the data to create a new list of animals who have "awesomeness" ratings of 5 or above.
  • Write the filtered list of animals to a new file called awesome_animals.csv. The new file should contain the exact same data columns and header row (animal, awesomeness) as the original file. The new file will differ only in the number of rows (it should have fewer).
  • At the end of the script, have it print the following line: There are X awesome animals., replacing the X value with the count of filtered animals. The X must be dynamically generated and inserted into the text using string formatting. In other words, do not hard-code the value into the string.

Lastly, you can run this script on the command line:

python filter_awesome_animals.py

Hints

In order to perform this work, you'll need to apply some string manipulation skills:

Submitting

Save and push your code to GitHub and submit the URL to your project in Canvas.