Python Forum
Exception: Returned Type Mismatch Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exception: Returned Type Mismatch Error
#1
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!
Reply


Messages In This Thread
Exception: Returned Type Mismatch Error - by devansing - Mar-06-2020, 12:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to access values returned from inquirer cspower 6 804 Dec-26-2023, 09:34 PM
Last Post: cspower
  Wrong type error rowan_bradley 6 1,223 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Type Error: Unsupported Operand jhancock 2 1,181 Jul-22-2023, 11:33 PM
Last Post: jhancock
  how to write exception error into logger mg24 3 982 Nov-15-2022, 04:20 PM
Last Post: insharazzak
  what type of exception to use? Skaperen 3 1,049 Sep-30-2022, 05:00 PM
Last Post: Skaperen
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,137 May-17-2022, 11:38 AM
Last Post: Larz60+
  Python Anytree - Is not of type 'NodeMixin' error georgebijum 3 2,092 May-05-2022, 01:43 PM
Last Post: Gribouillis
  SQLAlchemy Object Missing when Null is returned Personne 1 1,745 Feb-19-2022, 02:50 AM
Last Post: Larz60+
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 3,635 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Libraries installed with pipenv, but ModuleNotFoundError returned jpncsu 2 3,005 Sep-06-2021, 07:24 PM
Last Post: jpncsu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020