Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* Don't import anything, and you can use all built-ins/methods that are otherwise available. * adding definitions: You may add additional methods and functions in

image text in transcribedimage text in transcribed

* Don't import anything, and you can use all built-ins/methods that are otherwise available. * adding definitions: You may add additional methods and functions in support of your solution. * displaying things: _str__and_ _repr_are used by many other places in Python to get a string representation of the object. Specifically, str() calls__str_, and repr() calls_repr__, on any objects they receive as arguments. _str__often generates a human-centric representation, appropriate for a human reading what is present.__repr_often generates a Python-centric representation. The goal of_repr__is actually to have a string that could be evaluated to re-generate an identical object. In general, we would quite prefer it to look like a valid constructor call, if possible. Ultimately, we can have the same representation in str _ and repr_ if we'd like; in fact, when we didn't explicitly describe two different string representations for_str__and__repr_ to return, we can define one in terms of the other, like this def _repr_(self): return str(self) Just remember the original intent of-st-vs-rep-. It's good practice to define-init- and_repr_immediately before writing any extra methods in a Python class at a minimum, and perhaps also eq_as well. str class PhonePlan: definit_(self, type, lines None): create/initialize instance variables for type and the list of lines in the plan. When lines is not provided, use an empty list as its initial value. Create an instance variable calls to keep a list of calls made/received by any line of this plan, initialize it to be an empty list. Also create instance variables for balance, rollover_mins, and mins_to_pay, all starting at zero defstr_(self): create/return a string similar to: "PhonePlan (PlanType (25.50,_200,_0.50, True),[],_[])" See test cases for more examples. Hint: when obtaining strings for the lists of lines/calls, how can you rely upon other str or repr definitions to make this a short/trivial method to write? defrepr__(self): create/return a string identical to the__str_output def activate_all (self): make sure every line in this plan is active after calling this method. def deactivate_all(self): make sure every line in this plan is inactive after calling this method. * Don't import anything, and you can use all built-ins/methods that are otherwise available. * adding definitions: You may add additional methods and functions in support of your solution. * displaying things: _str__and_ _repr_are used by many other places in Python to get a string representation of the object. Specifically, str() calls__str_, and repr() calls_repr__, on any objects they receive as arguments. _str__often generates a human-centric representation, appropriate for a human reading what is present.__repr_often generates a Python-centric representation. The goal of_repr__is actually to have a string that could be evaluated to re-generate an identical object. In general, we would quite prefer it to look like a valid constructor call, if possible. Ultimately, we can have the same representation in str _ and repr_ if we'd like; in fact, when we didn't explicitly describe two different string representations for_str__and__repr_ to return, we can define one in terms of the other, like this def _repr_(self): return str(self) Just remember the original intent of-st-vs-rep-. It's good practice to define-init- and_repr_immediately before writing any extra methods in a Python class at a minimum, and perhaps also eq_as well. str class PhonePlan: definit_(self, type, lines None): create/initialize instance variables for type and the list of lines in the plan. When lines is not provided, use an empty list as its initial value. Create an instance variable calls to keep a list of calls made/received by any line of this plan, initialize it to be an empty list. Also create instance variables for balance, rollover_mins, and mins_to_pay, all starting at zero defstr_(self): create/return a string similar to: "PhonePlan (PlanType (25.50,_200,_0.50, True),[],_[])" See test cases for more examples. Hint: when obtaining strings for the lists of lines/calls, how can you rely upon other str or repr definitions to make this a short/trivial method to write? defrepr__(self): create/return a string identical to the__str_output def activate_all (self): make sure every line in this plan is active after calling this method. def deactivate_all(self): make sure every line in this plan is inactive after calling this method

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions