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
#2
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 273 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Libraries installed with pipenv, but ModuleNotFoundError returned jpncsu 2 215 Sep-06-2021, 07:24 PM
Last Post: jpncsu
  pywin32 Illustrator Throwing Exception Error matthewsjc1 7 354 Aug-27-2021, 02:43 AM
Last Post: Larz60+
  Strange error ValueError: dimension mismatch Anldra12 0 179 Aug-17-2021, 07:54 AM
Last Post: Anldra12
  ValueError: dimension mismatch Anldra12 0 416 Jul-17-2021, 04:46 PM
Last Post: Anldra12
  Incorrect Type Error milkycow 4 457 Jun-25-2021, 06:04 AM
Last Post: milkycow
Star Type Error: 'in' object is not callable nman52 3 652 May-01-2021, 11:03 PM
Last Post: nman52
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 720 Apr-13-2021, 10:33 AM
Last Post: deanhystad
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 1,442 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  Type Error in Python MarcusB 3 588 Mar-30-2021, 06:34 PM
Last Post: buran

Forum Jump:

User Panel Messages

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