Question

Write a Python function that displays a one-year calendar for any year. The program should prompt...

Write a Python function that displays a one-year calendar for any year. The program should prompt the user for a year (past, present or future). Then the program should calculate, the weekday for Jan 1 for that year. there is an equation for calculating this value, which is given as: day = R(1+5R(Y-1,4)+4(Y-1,100)+6R(Y-1,400),7) R(x,y) is remainder after the division of x by y, and Y is the year. The equation produces a value between 0 and 6, where 0 is Sunday, 1 is Monday,….6 is Saturday.

I am having trouble implementing this equation correctly in Python3. I am wondering how I would write this. Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]

days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

Y = int(input("Enter year: "))

day = (1+5*((Y-1)%4)+4*((Y-1)%100)+6*((Y-1)%400))%7

if (((Y % 4 == 0) and (Y % 100 != 0)) or (Y % 400 == 0)):

    days[1] += 1

for i in range(12):

    print("\t"+months[i]+", "+str(Y))

    for j in range(7):

        print("%3s"%dayNames[j], end=' ')

    print()

    print('    '*day, end='')

    for j in range(1, days[i]+1):

        print("%3d"%j, end=' ')

        if (j+day)%7==0:

            print()

    print("\n")

Add a comment
Know the answer?
Add Answer to:
Write a Python function that displays a one-year calendar for any year. The program should prompt...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT