Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a constructor with parameters self, num_mins and num_messages. num_mins an

ID: 3764744 • Letter: W

Question

Write a constructor with parameters self, num_mins and num_messages. num_mins and num_messages should have a default value of 0. Sample output for the given program:

GIVEN:

class PhonePlan:
# FIXME add constructor

def print_plan(self):
print('Mins:', self.num_mins, end=' ')
print('Messages:', self.num_messages)

'''Your solution goes here'''

my_plan = PhonePlan(200, 300)
dads_plan = PhonePlan()

print('My plan...', end=' ')
my_plan.print_plan()

print('Dad's plan...', end=' ')
dads_plan.print_plan()

Explanation / Answer

class PhonePlan:
   def __init__(self, a=0, b=0):
       self.num_mins=a
       self.num_messages=b
   def print_plan(self):
       print('Mins:', self.num_mins, end=' ')
       print('Messages:', self.num_messages)
  
my_plan = PhonePlan(200, 300)
dads_plan = PhonePlan()
print('My plan...', end=' ')
my_plan.print_plan()
print('Dad's plan...', end=' ')
dads_plan.print_plan()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote