44.5k views
2 votes
In Python

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

User Thahir
by
3.5k points

1 Answer

7 votes

class Messaging:

txt = ""

first = 0

second = 0

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

self.txt = input("Who's plan is this? ")

self.first = num_mins

self.second = num_messages

def print_Something(self):

print(f"{self.txt} Mins: {self.first} Messages: {self.second}")

obj = Messaging(100, 100)

obj.print_Something()

If you want to change what's printed to the console, just manipulate the values in Messaging(). Leave them blank for 0.

User Ahmed Shaqanbi
by
4.5k points