CS1951A | Programming Pre-Quiz

python pre-quiz

This quiz is designed to assess your Python coding ability. You are not necessarily expected to know Python when starting the course, but you should be able to pick it up quickly.

If you have never programmed in Python before, we recommended going to the resources page and exploring some of the Python resources provided there.

All of the code for this assignment is stored locally in your browser. If you wish to explore it on your own machine, we recommend saving the code to a .py file as well as saving the associated .txt documents.

In order to measure your progress, we have provided a function named tests. Do not modify these or else we cannot test your progress. These will be used to ensure that your code runs correctly.

There are additional specifications for each question written as comments. If you have questions, please post a question on Piazza or email the TA list (but please post a question first).

During this quiz, you will be working up to a small program that will be able to read lyrics and parse them by who is singing.

example

Here is a quick and easy example to get you started and see how our code runs. If you click the run button right now, you'll receive an AssertionError. To fix this, follow the comments!

problem 1

First, write a function that finds the maximum value in a list. You can assume that all of the elements in the list are numbers.

problem 2

Next, write a function that returns the number of words in a given string. Look at the split method for how to split strings in Python.

problem 3

Now you're going to work with files. Write a function that, when given the path to a file, opens the file and reads its contents into a list. Next, you'll write a function that, given a list of strings, returns the highest wordcount from all of the strings. You may optionally strip whitespace using the strip function, but this is not needed.

You can read about working with files in Python here. Additionally, for the second function we're using multiple returns by wrapping the return value in a tuple. You can read more about that here.

problem 4

Now you'll be writing a function that identifies whether a line from a lyrics file is a lyric or a heading, like [HAMILTON] Using that, we'll make a list of all the cast members in our two files. Try to avoid duplicates, perhaps using a set. (Although it isn't strictly necessary to do so to pass the tests, it will help you in the next part.)

problem 5

Now you'll build our final program. Building off of what we did previously, you'll be building a dictionary (hash table) that maps from character to a list of all the lines they sing.