Design a Python class for a calendar month You class should

Design a Python class for a calendar month. You class should have the following methods: __init___(self, name, days, first): start is the day of the week that the first falls on. get Days(self): returns the number of days getFirst(self): returns the first day of the month Add a main() method to the script that creates a couple month objects and calls the three get() methods of each to display to the screen.

Solution

CODE:

class calMonth(object):
def __init__(self,name,days,first):
#Here the values from the object are taken and assigned to variables
self.name=name
self.days=days
self.first=first
print(\"Object Initialized\")
#On succesful assignment print statement will be executed

def getName(self):
return self.name
#Each of the get functions retrive the data
  
def getDays(self):
return self.days
  
def getFirst(self):
return self.first
  
  
def main():
obj=calMonth(\"John\",30,\"Sunday\")
#Give values to assign to variables
name=obj.getName()
days=obj.getDays()
first=obj.getFirst()
  
print name,days,first

main()
#To call main function always we have to write the above statement

OUTPUT:

Object Initialized
John 30 Sunday

 Design a Python class for a calendar month. You class should have the following methods: __init___(self, name, days, first): start is the day of the week that

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site