Python Forum

Full Version: Exception: Returned Type Mismatch Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm taking an online course and have to submit the code through a 3rd party grading system. I have all of the scripts working as intended locally but when I submit it to the online grader, I'm getting some confusing errors –– the grader is running my functions with its own inputs.

Here's one example:

import datetime

def days_in_month(year, month):
    """
    Inputs:
      year  - an integer between datetime.MINYEAR and datetime.MAXYEAR
              representing the year
      month - an integer between 1 and 12 representing the month

    Returns:
      The number of days in the input month.
    """

    if (month < 1 or month > 12) or (year < 1 or year > 9999):
        return 0

    first_of_month = datetime.date(year, month, 1)

    if month == 12:
        first_of_next_month = datetime.date(year + 1, 1, 1)

    else:
        first_of_next_month = datetime.date(year, month + 1, 1)

        difference = first_of_next_month - first_of_month

        return difference.days
Error:
days_in_month(12, 12) expected 31 but received "(Exception: Returned Type Mismatch) Expected type 'int' but returned type 'NoneType'."
Appreciate any help -- thanks!
You're given the values that are passed to the function, so this should be quite straightforward to debug. Hint: what part of the code is being executed when those values are provided?

Also, in general, you should think about testing your cde thoroughly before submitting it somewhere. Check all the cases you can think of!