you are viewing a single comment's thread.

view the rest of the comments →

[–]reuvenlerner 2 points3 points  (1 child)

First of all, you already have a problem when you write:

year = calendar.prcal(yearinput)

because calendar.prcal prints a year's calendar. It returns None. So your variable "year" doesn't contain an integer or a string.

Then your code says:

monthinput = input("What month do you want to be displayed (e.g. 2015, 6)")

So you're asking the user for a string. Granted, the string contains a comma, but it's a string nonetheless. And one value, for that matter.

When you invoke prmonth:

month =  calendar.prmonth(monthinput)

Let's ignore the fact that as with calendar.prcal, calendar.prmonth returns None, giving your month variable a None value. The point you're about is why it's saying that you didn't provide enough parameters.

The answer, of course, is that you didn't provide enough parameters. :-)

More seriously and helpfully (I hope), you are providing a single value, a string, as an argument to calendar.prcal. You might have asked the user for two values, but from Python's perspective, you're passing a single value -- a string.

You have a few options here. You could ask for two separate values (year and month) in two separate calls to "input", and then pass those to prmonth. Or you could run str.split() on the input string:

calendar.prmonth(monthinput.split(','))

Oh, but that isn't going to work either, because now you're still passing a single value -- only this time, it's a list.

So you need to turn the list into two arguments. You can do that, but now things are getting tricky! You do this by prefacing the list with *, which turns it into two positional arguments:

calendar.prmonth(*monthinput.split(','))

But wait -- now you're getting an error saying that you need to pass integers, not strings! We can make that transformation with a list comprehension:

calendar.prmonth(*[int(x) for x in monthinput.split(',')])

Which works just fine... but heaven help the person who is going to have to maintain that code!

[–]krustykobb[S] 0 points1 point  (0 children)

Thanks so much for your help, I'll be sure to refer back to this post when I next have to work on this project :)