Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a python code!!! The Problem In storytelling, whether it is in mythic tales, novels, movies or video games, it is important that characters have

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

write a python code!!!

The Problem In storytelling, whether it is in mythic tales, novels, movies or video games, it is important that characters have a set of common attributes that work within the setting of the story. Most of the times characters don't exist in isolation but as part of larger groups. In this assignment you will create a squad (or gang) of such characters. Because a squad will be conformed by different characters, in this assignment you must reuse the Character class you created for Assignment 1. Specifically, the Squad class will be composed by four instances of the Character class. There will be one leader and three members. The Squad class should have the following: 1. A name for the squad. 2. Four different characters (one of which should be the leader). 2 3. The class constructor will receive the name of the squad and the four members, the first member should be the leader. 4. You must use name mangling to make all these instance variables inaccessible from outside the class. 5. There must be a getter for the name of the squad, but no setter. The name can't be changed after creating a squad. 6. The class must contain a method squad_size that will return the number of members in the squad (including the leader, thus after creation it should be 4). 7. There must be a mutator method add_member that receives a member and adds it to the squad. 8. There must be a mutator method remove_member that receives a member and removes it from the squad. If the leader of the squad is removed then the first member becomes the new leader. If a squad has only one remaining member then that member can't be removed. Thus, if this method receives as input the only remaining member, or a character that doesn't belong to the squad, then the method should do nothing. 9. You must implement a get_member method that receives an index and returns the correspond- ing member, index 0 will refer to the leader, index 1 to the first member, and so on. 10. You must also implement the __str_c method for printing the squad's info in a format similar to the one shown in the example. You should implement this method by reusing (calling) the --str-- method from the Character class. 11. You must implement a save_to_disk method that prints the squad's info to a file in text format. The info saved to disk should be the exact same info returned by the __str__ method from the Squad class. 12. You must also provide appropriate docstring documentation for classes and methods. 13. You must provide a driver script that creates four characters and add them to a squad and save the squad to disk. Then you should create a new character, add this new character to the squad and save the new squad to disk. Finally you should remove two characters from the squad, one of which should be the leader, then save the squad to disk and print it to console. Driver Script and Sample Run Continuing with our setting of the Wild West, we start by creating four different characters as shown in Figure 1: Billy the Kid, Diana Gold, Frank the Creep and James Montgomery. Then we create our squad, which we named as A weird gang, and save it to disk. After that we create a new character for Johnny Silverado, add him to the squad, and save the squad to a different file. The final part of the driver removes two characters from the squad: Frank the Creep and the leader Billy the Kid. After removing the squad leader, the first member should become the new leader. We finally save the squad to a different file and print it to console. from character import Character from squad import Squad # First we create the four initial characters for the squad henry = Character("Billy the Kid", "A dangerous outlaw", "Gunfighter", 3.2, 82) diana = Character("Diana Gold", "The richest merchant of the west", "Merchant", 5.4, 54) frank - Character("Frank the Creep", "Knows his knifes", "Butcher", 4.1, 40) james = Character("James Montgomery", "The fastest gun in the west", "Hired Gun", 2.1, 88) We create the squad and save it to disk squad = Squad("A weird gang", henry, diana, frank, james) squad.save_to_disk("squad_day1.txt") Johnny joins the squad johnny = Character("Johnny Silverado", "Fast and Furious", "Town Marshal", 2.9, 98) squad.add_member(johnny) squad.save_to_disk("squad_day2.txt") # and we lost the Billy and Frank the Butcher :( squad.remove_member(frank) squad.remove_member(henry) # Diana should now become the leader squad.save_to_disk("squad_day3.txt") print(squad) Figure 1: Driver program for testing the Squad class. Figure 2 shows the output of running the driver program. You can see that after removing Billy and Frank the squad has now Diana as the leader and two more members. You can also see the format used to print the squad of the squad, and the information for each character. Notice that the character information is printed in the same format as in the Character class. Figures 3, 4 and 5 show the contents for the three text files saved by the driver program. Very important note: you are not supposed to create the exact same squad and characters as in this example. You must create your own class with your own attributes, mutators and valid ranges. In a setting other than the Wild West. *** A weird gang *** LEADER: Diana Gold The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 1: James Montgomery The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 MEMBER 2: Johnny Silverado - Fast and Furious Profession: Town Marshal Draw speed: 2.9 Aim: 98 Process finished with exit code o Figure 2: Output for running the driver. # squad_day 1.txt > *** A weird gang *** LEADER: Billy the Kid A dangerous outlaw Profession: Gunfighter Draw speed: 3.2 Aim: 82 MEMBER 1: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 2: Frank the Creep Knows his knifes Profession: Butcher 12 Draw speed: 4.1 13 Aim: 40 MEMBER 3: James Montgomery The fastest gun in the west 15 Profession: Hired Gun 16 Draw speed: 2.1 17 Aim: 88 Figure 3: Content of the first file. 82 #squad_day2.txt X *** A weird gang *** LEADER: Billy the Kid A dangerous outlaw Profession: Gunfighter Draw speed: 3.2 Aim: MEMBER 1: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 2: Frank the Creep Knows his knifes Profession: Butcher Draw speed: 4.1 Aim: 40 MEMBER 3: James Montgomery The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 18 MEMBER 4: Johnny Silverado - Fast and Furious 19 Profession: Town Marshal 20 Draw speed: 2.9 21 Aim: 98 Figure 4: Content of the second file. CNP 5 squad_day3.txt *** A weird gang *** LEADER: Diana Gold The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 1: James Montgomery The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 MEMBER 2: Johnny Silverado Fast and Furious Profession: Town Marshal Draw speed: 2.9 Aim: 98 8 9 10 12 13 Figure 5: Content of the third file. The Problem In storytelling, whether it is in mythic tales, novels, movies or video games, it is important that characters have a set of common attributes that work within the setting of the story. Most of the times characters don't exist in isolation but as part of larger groups. In this assignment you will create a squad (or gang) of such characters. Because a squad will be conformed by different characters, in this assignment you must reuse the Character class you created for Assignment 1. Specifically, the Squad class will be composed by four instances of the Character class. There will be one leader and three members. The Squad class should have the following: 1. A name for the squad. 2. Four different characters (one of which should be the leader). 2 3. The class constructor will receive the name of the squad and the four members, the first member should be the leader. 4. You must use name mangling to make all these instance variables inaccessible from outside the class. 5. There must be a getter for the name of the squad, but no setter. The name can't be changed after creating a squad. 6. The class must contain a method squad_size that will return the number of members in the squad (including the leader, thus after creation it should be 4). 7. There must be a mutator method add_member that receives a member and adds it to the squad. 8. There must be a mutator method remove_member that receives a member and removes it from the squad. If the leader of the squad is removed then the first member becomes the new leader. If a squad has only one remaining member then that member can't be removed. Thus, if this method receives as input the only remaining member, or a character that doesn't belong to the squad, then the method should do nothing. 9. You must implement a get_member method that receives an index and returns the correspond- ing member, index 0 will refer to the leader, index 1 to the first member, and so on. 10. You must also implement the __str_c method for printing the squad's info in a format similar to the one shown in the example. You should implement this method by reusing (calling) the --str-- method from the Character class. 11. You must implement a save_to_disk method that prints the squad's info to a file in text format. The info saved to disk should be the exact same info returned by the __str__ method from the Squad class. 12. You must also provide appropriate docstring documentation for classes and methods. 13. You must provide a driver script that creates four characters and add them to a squad and save the squad to disk. Then you should create a new character, add this new character to the squad and save the new squad to disk. Finally you should remove two characters from the squad, one of which should be the leader, then save the squad to disk and print it to console. Driver Script and Sample Run Continuing with our setting of the Wild West, we start by creating four different characters as shown in Figure 1: Billy the Kid, Diana Gold, Frank the Creep and James Montgomery. Then we create our squad, which we named as A weird gang, and save it to disk. After that we create a new character for Johnny Silverado, add him to the squad, and save the squad to a different file. The final part of the driver removes two characters from the squad: Frank the Creep and the leader Billy the Kid. After removing the squad leader, the first member should become the new leader. We finally save the squad to a different file and print it to console. from character import Character from squad import Squad # First we create the four initial characters for the squad henry = Character("Billy the Kid", "A dangerous outlaw", "Gunfighter", 3.2, 82) diana = Character("Diana Gold", "The richest merchant of the west", "Merchant", 5.4, 54) frank - Character("Frank the Creep", "Knows his knifes", "Butcher", 4.1, 40) james = Character("James Montgomery", "The fastest gun in the west", "Hired Gun", 2.1, 88) We create the squad and save it to disk squad = Squad("A weird gang", henry, diana, frank, james) squad.save_to_disk("squad_day1.txt") Johnny joins the squad johnny = Character("Johnny Silverado", "Fast and Furious", "Town Marshal", 2.9, 98) squad.add_member(johnny) squad.save_to_disk("squad_day2.txt") # and we lost the Billy and Frank the Butcher :( squad.remove_member(frank) squad.remove_member(henry) # Diana should now become the leader squad.save_to_disk("squad_day3.txt") print(squad) Figure 1: Driver program for testing the Squad class. Figure 2 shows the output of running the driver program. You can see that after removing Billy and Frank the squad has now Diana as the leader and two more members. You can also see the format used to print the squad of the squad, and the information for each character. Notice that the character information is printed in the same format as in the Character class. Figures 3, 4 and 5 show the contents for the three text files saved by the driver program. Very important note: you are not supposed to create the exact same squad and characters as in this example. You must create your own class with your own attributes, mutators and valid ranges. In a setting other than the Wild West. *** A weird gang *** LEADER: Diana Gold The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 1: James Montgomery The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 MEMBER 2: Johnny Silverado - Fast and Furious Profession: Town Marshal Draw speed: 2.9 Aim: 98 Process finished with exit code o Figure 2: Output for running the driver. # squad_day 1.txt > *** A weird gang *** LEADER: Billy the Kid A dangerous outlaw Profession: Gunfighter Draw speed: 3.2 Aim: 82 MEMBER 1: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 2: Frank the Creep Knows his knifes Profession: Butcher 12 Draw speed: 4.1 13 Aim: 40 MEMBER 3: James Montgomery The fastest gun in the west 15 Profession: Hired Gun 16 Draw speed: 2.1 17 Aim: 88 Figure 3: Content of the first file. 82 #squad_day2.txt X *** A weird gang *** LEADER: Billy the Kid A dangerous outlaw Profession: Gunfighter Draw speed: 3.2 Aim: MEMBER 1: Diana Gold - The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 2: Frank the Creep Knows his knifes Profession: Butcher Draw speed: 4.1 Aim: 40 MEMBER 3: James Montgomery The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 18 MEMBER 4: Johnny Silverado - Fast and Furious 19 Profession: Town Marshal 20 Draw speed: 2.9 21 Aim: 98 Figure 4: Content of the second file. CNP 5 squad_day3.txt *** A weird gang *** LEADER: Diana Gold The richest merchant of the west Profession: Merchant Draw speed: 5.4 Aim: 54 MEMBER 1: James Montgomery The fastest gun in the west Profession: Hired Gun Draw speed: 2.1 Aim: 88 MEMBER 2: Johnny Silverado Fast and Furious Profession: Town Marshal Draw speed: 2.9 Aim: 98 8 9 10 12 13 Figure 5: Content of the third file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions