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 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 In this assignment you will create a class called Character which creates a character in a setting of your choosing. The class should have the following: 1. A name for the character. 2. A brief description (less than 100 characters long). 3. Exactly three attributes of type string, float and integer. 4. The class constructor will receive the name, description and the values for the different attributes and use them to create an instance of the class. 5. You must use name mangling to make all these attributes inaccessible from outside the class (including the name and description). 6. There must be getters for all these attributes, and a setter for the description. The name however, can't be changed after creating a Character. 7. The float attribute should have a setter that checks whether the provided value is in a given interval and only updates the attribute if that's the case. 8. There must be a mutator method for increasing the integer attribute in some amount (in the our example we use a level_up_aim() method that increases the aim by 5%). 9. You must implement the __str__ method for printing the character's info in a format similar to the one shown in the example. 10. You must also provide appropriate docstring documentation for classes and methods. 11. You must provide a driver script that creates an instance of a character, modifies and prints it, as shown in the example. Example Setting If we were creating a class for an Old West setting we could define characters with attributes such as profession (which would be a string attribute), aim (an integer) and draw speed (a float). The aim could refer to the effectiveness (percent) of hitting a target when firing a gun. The draw speed would be the speed at which the character can draw their gun in a gun fight, measured in seconds. The profession could be something like "Outlaw, Town Marshal", "Merchant", "Banker", "Farmer", etc. In such a setting one of our characters could be Billy the Kid, whose birth name was actually Henry McCarty. His attributes could be the following: Name: Billy the Kid Description: A dangerous outlaw Profession: Gunfighter Draw speed: 3.2 seconds Aim: 82% Driver Script and Sample Run In the driver script you must create a character of your own and then print its attributes. Afterwards you should call the mutator method that levels up the integer attribute (in our case we increase the aim by 5%); and also call the setter of the attribute that checks for a range. As you can see in the driver script in Figure 1, this attribute is the draw speed. Which in our setting has a valid range of (0.5,5), thus the second call to the setter is ignored by the Character class and no update is performed. Finally, you can also see in Figure 1 that the we print a message indicating how the attributes have changed, and we do so making use of the getter methods. from character import Character # Let's create a character for Billy the Kid henry = Character("Billy the Kid", "A dangerous outlaw", "Gunfighter", 3.2, 82) # And print his stats print(henry) ** Billy the kid has been training # His ain has improved and he draws his gun faster henry.level_up_aimo henry.set_draw_speed(3.0) # this is the new valid attribute value henry.set_draw_speed(-7.0) this is an invalid value, thus the attribute won't change Let's print that print(" Billy the Kid has been training...") print(f"His aim now is {henry.get_aim()} effective, f"and he draws his gun in (henry.get_draw_speed()} seconds") Figure 1: Driver program for testing the Character class. Figure 2 shows the result of running the driver program. You can see the format used to print the name, description and attributes of the character. You should follow a similar format for your class. You can also see how the call to the setter of the draw speed (with the parameter -7) had no effect in changing the attribute value (which was effectively changed to 3 afterwards) Very important note: you are not supposed to create the exact same class and character 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. Billy the Kid A dangerous outlaw Profession: Gunfighter Draw speed: 3.2 Aim: 82 Billy the Kid has been training... His aim now is 87% effective, and he draws his gun in 3.0 seconds Process finished with exit code Figure 2: Output for running the driver

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

Step: 3

blur-text-image

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago