# Difference between revisions of "Python Workshops for Beginners/Saturday September 27th homework"

Hopefully you haven't forgotten too much from the last few sessions. Here are some homework problems you should try out before the next session on October 25. The exercises are based on the Shakespeare and Wordplay exercises from last time. Regardless of which afternoon session you attended, you should be able to do both, unless otherwise specified.

Remember: indentation in Python matters!

## Setup

• Unzip the file
• Use the command line to navigate into the directory PWFB-homework

## Shakespeare Exercises

Here's a link to the Shakespeare handout from last time: []

Using the command line (or "command prompt"), enter into the directory named shakespeare-exercises.

Exercise 1

Write a program that creates a dictionary with keys as the characters from A Midsummer Night's Dream and the values being the number of times each particular character had a speaking part.

To get started, import the two modules which provide the character list and text of the play:

```>>> import summerChar
>>> import summerNight
```

To access the list of characters, set the following variable:

```>>> characters = summerChar.SummerChar
```

To access the text of the play as a list (each line is an entry in the list):

```>>> lines = summerNight.SummerNight
```

Exercise 2

You must have completed exercise 1 to do exercise 2. If you cannot complete exercise 1, just make up values for dictionary and try this exercise anyway.

Write a program which determines the percentage of the total number of speaking parts each character had. Use the dictionary you created in exercise 1. Here's an example to make the problem more clear:

Suppose we had the following dictionary of characters, where the values represent the number of speaking parts each has:

```>>> characters = {Harry: 3, Hermione: 4, Ron: 5}
```

A program which determines what percentage of the total each had might output something like this:

```Ron has 41.666% of the speaking parts.
Harry has 25% of the speaking parts.
Hermione has 30% of the speaking parts.
```

## Wordplay Exercises

Here's a link to the Wordplay handout if you need a review.

Exercise 3

Exercise 4