In: Computer Science
Exercise: Add Monster Cast Member
-------------------------
### Description
In this series of exercises, you will create functions
to create, modify and examine dictionaries that
represent characters in an animated film, and the
cast members who voice the characters. The
keys of the dictionary will be character names.
The values in the dictionary will be voice actor
names.
For this exercise, you will create a function that
adds an entry to a dictionary. They key is a
character name, and the value is the name of the
voice actor.
### Files
* `monsterfunctions.py` : set of functions to work with monster cast dictionaries.
### Function Name
`add_cast_member`
### Parameters
* `monsters`: a dictionary
* `character`: a string, the name of a character
* `cast_member`: a string, the name of an actor
### Action
Adds an entry to `monsters`, using `character` as the
key and `cast_member` as the value.
### Return Value
The modified dictionary.
def create_monster_cast():
d1={}
return d1
def add_cast_member(monsters, character, cast_member):
dict = {
"monsters":monsters,
"character":character,
"cast_member":cast_member
}
return dict
SOLUTION:
The following solution has been provided based on my understanding of the problem. It has been implemented to create a dictionary, add dictionary items and finally print dictionary values.
*** The dictionary representation and function may vary from what is shown in the question****
PROGRAM
# Create an empty dictionary
def create_monster_cast():
d1 = {}
return d1
# Add cast to a dictionary
def add_cast_member(monsters, character, cast_member):
dictionary = monsters
dictionary[character] = cast_member
return dictionary
# Create monster dictionary
monsters = create_monster_cast()
# Add Cast to Monster Dictionary
monsters = add_cast_member(monsters, 'James P. "Sulley" Sullivan', 'John Goodman')
monsters = add_cast_member(monsters, 'Michael "Mike" Wazowski', 'Billy Crystal')
monsters = add_cast_member(monsters, 'Boo', 'Mary Gibbs')
monsters = add_cast_member(monsters, 'Randall Boggs', 'Steve Buscemi')
monsters = add_cast_member(monsters, 'Randall Boggs', 'Steve Buscemi')
monsters = add_cast_member(monsters, 'Henry J. Waternoose III', 'James Coburn');
# Print Dictionary values
print('Monster Cast : ')
for key, value in monsters.items():
print(format(key, "<30"), ': ', end='')
print(value)
SCREENSHOT
Note:
The list of 6 characters along with their cast have been added to the monster dictionary and data displayed.
Hope this helps.