Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (20.3k points)
edited by

I need to make a calendar in Python that displays a formatted table of a month when the user inputs the days in the month and the date of the first Sunday. For example, if the user inputs 30 days and the first Sunday is 6, then the calendar would look like this.

I have no idea which direction to go when going about this problem. I could use some help on how to approach this question. So far I've only learned about booleans, conditionals, loops, etc. Also not allowed to import the calendar. Thank you.

1 Answer

0 votes
by (40.7k points)

Try the code given below:

day_count=30

first_sunday=6

if first_sunday != 1:

    i=int(first_sunday)-7

else:

    i=1

count=1

print "Su  Mo  Tu  We  Th  Fr  Sa"

while i<=day_count:

    if i<1:

        print ("%-3s" % (" ")),

    else:

        print ("%-3s" %  (str(i))),

    if i>0 and count % 7 == 0:

        print ""

    i=i+1

    count = count+1

Browse Categories

...