Question

In: Computer Science

Exercise: Add Monster Cast Member ------------------------- ### Description In this series of exercises, you will create...

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

Solutions

Expert Solution

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****

  • The function create_monster_cast() will create an empty dictionary.
  • The function add_cast_member(monsters, character, cast_member) as shown accepts 3 arguements. The first being the dictionary name, the second being the character name(key) and third cast member name(value).
  • Using character as the key, the value of cast_member is assigned to the dictionary monsters.
  • The modified dictionary is returned.

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.


Related Solutions

PYTHON Exercise: Accelerate Method ------------------------- ### Description In this exercise, you will add to your `Car`...
PYTHON Exercise: Accelerate Method ------------------------- ### Description In this exercise, you will add to your `Car` class a method to accelerate the speed of an instance. ### Class Name `Car` ### Method `accelerate()` ### Parameters * `self` : the `Car` object to use * `delta_speed` : a number, the desired value to add to the speed data member. ### Action Adds `delta_speed` to the speed of the object. If the new speed is too fast, then set the speed to...
Description: In this program, you'll reuse the Monster data type you wrote in LA11A. Then, you'll...
Description: In this program, you'll reuse the Monster data type you wrote in LA11A. Then, you'll write a function that accepts a Monster as an argument by reference, then print the Monster to the screen. Again, this will be structured as a guided multiple choice quiz where you will choose the appropriate code for a program. After you have gotten a perfect score, write out the program and compile and run it to see it in action. Instructions: Choose the...
Create a student class that stores name, registration number and percentage, grade. Add member functions -...
Create a student class that stores name, registration number and percentage, grade. Add member functions - Read( string n, int r, float p): Read function that accepts parameter - Display(): To display student’s information - CalculateGrade()
For this program you will add and test 2 new member functions to the class in...
For this program you will add and test 2 new member functions to the class in //************************ intSLList.h ************************** // singly-linked list class to store integers #ifndef INT_LINKED_LIST #define INT_LINKED_LIST class IntSLLNode { public: IntSLLNode() { next = 0; } IntSLLNode(int el, IntSLLNode *ptr = 0) { info = el; next = ptr; } int info; IntSLLNode *next; }; class IntSLList { public: IntSLList() { head = tail = 0; } ~IntSLList(); int isEmpty() { return head == 0; }...
THIS QUESTION IS BASED UPON JAVA PROGRAMMING. Exercise 1 In this exercise, you will add a...
THIS QUESTION IS BASED UPON JAVA PROGRAMMING. Exercise 1 In this exercise, you will add a method swapNodes to SinglyLinkedList class. This method should swap two nodes node1 and node2 (and not just their contents) given references only to node1 and node2. The new method should check if node1 and node2 are the same nodes, etc. Write the main method to test the swapNodes method. Hint: You may need to traverse the list. Exercise 2 In this exercise, you will...
Create a class DogWalker member List <String>doggies method: void addDog(String name ) //add dog to the...
Create a class DogWalker member List <String>doggies method: void addDog(String name ) //add dog to the List method: void printDogList() //print all dogs in list /* You’ll need an index. Iterate over your list of dog names in a while loop. Use your index to “get” the dog at the current index When you ‘find’ your dog name in the list, print it out */ Method: void findDogUsingWhile(String dogName) /* You’ll need an index. Iterate over your list of dog...
You are a member of a research team that has been asked to create a proposal...
You are a member of a research team that has been asked to create a proposal for a study design to address a potential cholera outbreak in Puerto Rico. The Centers for Disease Control and Prevention is sending a team of epidemiologists to Puerto Rico to investigate cases of cholera associated with Hurricane Maria. As a team member, you are asked to research study design for the upcoming investigation, identifying the advantages and disadvantages of the following four designs as...
function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' //...
function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' // This variable should be assigned a new object // In this object create three key:value pairs // The keys should be: 'name', 'city', 'favoriteAnimal' // The values should be strings associated with the keys. // return the variable 'aboutMe' } function exerciseTwo(animal){ // Exercise Two: In this exercise you will be given an object called 'animal' // Create a new variable called 'animalName' //...
In this exercise, the first of a series, we will make connections between the physics you...
In this exercise, the first of a series, we will make connections between the physics you have been learning (in this case, kinematics) and how it is used by people in their work and research. Today we consider an example from kinesiology research, based on a 2000 paper from the Journal of Measurement in Physical Education and Exercise Science (nota bene: you do not have to read this paper, or any of the hyperlinks to follow the exercise – it...
Here is a program that computes Fibonacci series. Can you add comments to variables and functions...
Here is a program that computes Fibonacci series. Can you add comments to variables and functions of every functions? For example, what are these variables meaning? What "for" function do on this program? Describe important section of code to text file. For example, which section of this code important? Why? Thank you all of help. #include<iostream> using namespace std; int main() { int arr[100]; int n1, n2; cin>>n1; arr[0] = 0; arr[1] = 1; for(int i = 2;i<n1;i++){ arr[i] =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT