0

i am trying to make a code that print out calendar with some given months and years. My code look like this:

#!/usr/bin/python3
"""import calender"""

import calendar
import datetime

""" begin function """


def get_the_first_day_of_the_week(month, year):
    day_of_week = datetime.date(year, month, 1).weekday()
    return


def print_out_calender(months, years):
    this_month = int(months)
    this_year = int(years)
    new = get_the_first_day_of_the_week(this_month, this_year)
    new = int(new)
    calendar.setfirstweekday(new)
    calendar.monthcalendar(this_month, this_year)
    return


print_out_calender(12, 2017)

i expect it to print out matrix of date but i got an error like this: Traceback (most recent call last):

  File "./practice12.py", line 25, in <module>
    print_out_calender(12, 2017)
  File "./practice12.py", line 19, in print_out_calender
    new = int(new)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

i am new to python and coding so can somebody tell me why?

1
  • 1
    Did you mean return day_of_week inside of get_the_first_day_of_the_week? Commented Aug 23, 2017 at 6:18

4 Answers 4

3
new = get_the_first_day_of_the_week(this_month, this_year)

assigns the return value of get_the_first_day_of_the_week() to new.

However, get_the_first_day_of_the_week() returns nothing, i.e. None.

Change the function to return something (presumably day_of_the_week) and it should work.

Sign up to request clarification or add additional context in comments.

Comments

0

That's because new is None in the code. int cannot take None type arguments.

Comments

0

Return day_of_week from get_the_first_day_of_the_week

Comments

0

You are returning None in get_the_first_day_of_the_week function. Either return day_of_week or make day_of_week a global variable.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.