2

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 with one plan created with input: 200 300, one plan created with no input, and one plan created with input: 500

**My plan... Mins: 200 Messages: 300

Dad's plan... Mins: 0 Messages: 0

Mom's plan... Mins: 500 Messages: 0**

class PhonePlan:

    # add constructor

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


my_plan = PhonePlan(int(input()), int(input()))
dads_plan = PhonePlan()
moms_plan = PhonePlan(int(input()))

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

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

print('Mom\'s plan...', end= ' ')
moms_plan.print_plan()

How would I complete this code?

1
  • 1
    What have you tried so far? Commented Mar 31, 2020 at 20:15

5 Answers 5

3
class PhonePlan:
   
    def __init__(self, minutes=0, messages=0):
        self.num_mins=minutes
        self.num_messages=messages

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


my_plan = PhonePlan(int(input()), int(input()))
dads_plan = PhonePlan()
moms_plan = PhonePlan(int(input()))

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

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

print('Mom\'s plan...', end= ' ')
moms_plan.print_plan()
Sign up to request clarification or add additional context in comments.

Comments

0

You need to define a constructor in your class.

class PhonePlan:
    def __init__(self, minutes=0, messages=0):
        self.minutes = minutes
        self.messages = messages

    def print_plan(self):
        print('Mins:', self.minutes)
        print('Messages:', self.messages)


my_plan = PhonePlan(540, 10)
dads_plan = PhonePlan()
moms_plan = PhonePlan(56)

print('My plan...')
my_plan.print_plan()

print('Dad\'s plan...')
dads_plan.print_plan()

print('Mom\'s plan...')
moms_plan.print_plan()

Comments

0

for this specific question you are asked to make a construct with parameters 'self' 'num_mins' and 'num_messages' and equal the last two to 0.

      def __init__(self, num_mins=0, num_messages=0):
            self.num_mins = num_mins
            self.num_messages = num_messages

this sets all 3 parameters (and the two to 0 that are asked for).

Comments

0

This is what worked for me.

def __init__(self, minutes=0, messages=0):
    self.num_mins = minutes
    self.num_messages = messages

Comments

-1

This is correct answer for this lab:

def __init__(self, num_mins=0, num_messages=0):
    self.num_mins = num_mins
    self.num_messages = num_messages

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.