Question: Lab 3.3.2 Writing and using your own functions basics Objectives Familiarize the student with: projecting and writing parameterized functions; utilizing the return statement; utilizing her/his

Lab 3.3.2 Writing and using your own functions basics

Objectives

Familiarize the student with:

projecting and writing parameterized functions;

utilizing the return statement;

utilizing her/his own functions.

Scenario

Your task is to write and test a function which takes two arguments (a year and a month) and returns the number of days for the given month/year pair (yes, we know that only February is sensitive to the year value, but we want our function to be universal). The initial part of the function is ready. Now, convince the function to return None if its arguments dont make sense.

Of course, you can (to be honest: you should!) use the previously written and tested function. It may be very helpful (we cannot say anything more, sorry). We encourage you to use a list filled with the months lengths. You can create it inside the function this trick will significantly shorten the code.

Weve prepared a testing code. Expand it to include more test cases.

def IsYearLeap(year):

#

# your code is already here

#

def DaysInMonth(year,month):

#

# put your new code here

#

testyears = [1900, 2000, 2016, 1987]

testmonths = [ 2, 2, 1, 11]

testresults = [28, 29, 31, 30]

for i in range(len(testyears)):

yr = testyears[i]

mo = testmonths[i]

print(yr,mo,"->",end="")

result = DaysInMonth(yr,mo)

if result == testresults[i]:

print("OK")

else:

print("Failed")

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!