Question: Python Class question. how to modify values in class? I have so far done the __init__ __str__ __repr as below with black screen below. I

Python Class question. how to modify values in class?

I have so far done the __init__ __str__ __repr as below with black screen below. I need help the all rest defs in the white screen. Thank you in advance

Python Class question. how to modify values in class? I have so

far done the __init__ __str__ __repr as below with black screen below.

!!!!!UPDATED!!!!! 

class Line:

def __init__( self, name, area_code, number, is_active=True): constructor of a telephone line:

create/initialize instance variables for name, area_code, number and is_active. Assume area_code is a

three-digit integer with no leading 0/1; assume number is a seven-digit integer with no leading 0/1.

def __str__(self): create/return a string as in this example: "703-9931530(GMU CS)"

def __repr__(self): create/return a string as in this example: "Line('GMU CS',703,9931530)"

def __eq__(self, other): determine if this object (self) is equivalent to other. Two lines are

considered equal if they have the same area code and same number. Return True if they are equal; returnFalse otherwise. Examples in the test cases.

o By providing this method, == can be used to compare two lines based on area_codeumber only.

def activate(self): set is_active of this object to be True.

def deactivate(self): set is_active of this object to be False.

class Call:

def __init__(self, caller, callee, length):create/initialize instance variables for all three non-

self parameters. Assume caller and callee are Lines and that length is an integer. Check and raiseCallErrorfor the following cases:

o If either caller or callee is inactive, raise CallError with error message as in this example:"line703-9931530(GMU CS)notactive". If both caller and callee are inactive, only raise the error for caller.

o If caller and callee are equivalent (with the same area_code and number), raise CallErrorwith error message as in this example: "line703-9931530(GMU CS)cannotcallitself".

o If length is negative, raise CallError with error message as in this example:"negativecalllength:-5".

def __str__(self): create/return a string as in this example: "Call(Line('GMU CS',703,9931530),Line('GMU',703,9931000),20)" Hint: when obtaining strings for the lines, how can you rely upon str or repr definitions of lines to make this a short/trivial method to write?

def __repr__(self): create/return a string identical to the __str__ output.

def is_local(self): return True if both caller and callee have the same area_code; return False

otherwise.

class CallError(Exception): 

Be sure to include the (Exception) portion above in your class declaration, so that this is an extension of the

Exception class (with all the exception properties that implies: it can be raised).

def __init__(self, msg): create/initialize instance variable for msg.

def __str__(self): create/return a string based on msg as in this example:"CallError:negativecalllength:-5" #msg=="negativecalllength:-5"

def __repr__(self): create/return a string based on msg as in this example:"CallError('negativecalllength:-5')" #msg=="negativecalllength:-5"

class PhonePlanError(Exception): 

Be sure to include the (Exception) portion above in your class declaration.

def __init__(self, msg): create/initialize instance variable for msg.

def __str__(self): create/return a string based on msg as in this example:"PhonePlanError:duplicatedlinetoadd" #msg=="duplicatedlinetoadd"

def __repr__(self): create/return a string based on msg as in this example:"PhonePlanError('duplicatedlinetoadd')" #msg=="duplicatedlinetoadd"

 

class PhonePlan: def init__(self, type, Lines-None): self.type type if lines is None lines self.lines line self.calls self.balance e self.rollover_mins self.mins_to_pay def str(self): return "PhonePlan("+str(self.type)+", "+str(self.lines)+", "+str(self.calls)+")" def__repr(self): return "PhonePlan("+str(self.type)+", "+str(self.lines)+", "+str(self.calls)+")" class PhonePlan: . def-init-(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 def-str-(self) : create/return a string similar to: PhonePlan(PlanType(25.50,_200,0.58, 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? . def__repr__(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. def add_call(self, cal1): add the given call to the end of the list of calls. Either caller or callee of the given call should be a line of this plan, otherwise do not append but raise a PhonePlanError with error message "call_cannot_be_added". If call can be added, check whether the call is billable based on the following rules . A local call is free and not billable; Hint: use your Call class's is local method to help. A call made between two lines of this plan is free and not billable o o For a billable call, increment instance variable mins_to_pay based on the length of the call. All updates made in this method change instance variables directly and the method returns None def remove_cal1(self, call): remove the given call from the list of calls and returns None. If call is not present in the list, raise a PhonePlanError with error message "no_such_call_to_remove" . . def add calls (self, calls): accept a list of calls, use add_call () to add each to the end of the list of calls and update mins_to_pay accordingly. Count and return the number of calls that are successfully added into the call record. Requirement and Hint: you must call add_call; exception handling can help def make_call(self, caller, callee, length): create a call based on caller, callee, and length, then add it to the end of the list of calls and update mins_to_pay accordingly. Return True if the call is created and added successfully; return False if . The call cannot be created due to a CallError; or The call cannot be added due to a PhonePlanError (neither caller nor callee belongs to this o o an . def mins_by_line(self, line): calculate and return the number of call minutes associated with the given line in this plan based on the current list of calls. A call is associated with a line if the line is either its caller or callee. Return zero if the given line is not included in this plan. Hint: Make sure your Line class's eqmethod works, first. class PhonePlan: def init__(self, type, Lines-None): self.type type if lines is None lines self.lines line self.calls self.balance e self.rollover_mins self.mins_to_pay def str(self): return "PhonePlan("+str(self.type)+", "+str(self.lines)+", "+str(self.calls)+")" def__repr(self): return "PhonePlan("+str(self.type)+", "+str(self.lines)+", "+str(self.calls)+")" class PhonePlan: . def-init-(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 def-str-(self) : create/return a string similar to: PhonePlan(PlanType(25.50,_200,0.58, 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? . def__repr__(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. def add_call(self, cal1): add the given call to the end of the list of calls. Either caller or callee of the given call should be a line of this plan, otherwise do not append but raise a PhonePlanError with error message "call_cannot_be_added". If call can be added, check whether the call is billable based on the following rules . A local call is free and not billable; Hint: use your Call class's is local method to help. A call made between two lines of this plan is free and not billable o o For a billable call, increment instance variable mins_to_pay based on the length of the call. All updates made in this method change instance variables directly and the method returns None def remove_cal1(self, call): remove the given call from the list of calls and returns None. If call is not present in the list, raise a PhonePlanError with error message "no_such_call_to_remove" . . def add calls (self, calls): accept a list of calls, use add_call () to add each to the end of the list of calls and update mins_to_pay accordingly. Count and return the number of calls that are successfully added into the call record. Requirement and Hint: you must call add_call; exception handling can help def make_call(self, caller, callee, length): create a call based on caller, callee, and length, then add it to the end of the list of calls and update mins_to_pay accordingly. Return True if the call is created and added successfully; return False if . The call cannot be created due to a CallError; or The call cannot be added due to a PhonePlanError (neither caller nor callee belongs to this o o an . def mins_by_line(self, line): calculate and return the number of call minutes associated with the given line in this plan based on the current list of calls. A call is associated with a line if the line is either its caller or callee. Return zero if the given line is not included in this plan. Hint: Make sure your Line class's eqmethod works, first

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!