Python Forum
Problem with code to calculate weekday for leap years!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with code to calculate weekday for leap years!
#3
Thank you very much!

Now it runs perfectly! ;)
Made three separate "and"-operations instead of the nested if:s. Works like a charm!

elif month == 14 and (year+1)%400 == 0:
    while day>29 or day<1:
        day = int(input("Day:"))
        if day<1 or day>29:
            print("Out of allowed range 1 - 29")

elif month == 14 and (year+1)%100 != 0:
    while day>28 or day<1:
        day = int(input("Day:"))
        if day<1 or day>28:
            print("Out of allowed range 1 - 28")

elif month == 14 and (year+1)%4 == 0 and (year+1)%400 == 0 and (year+1)%100 != 0:
    while day>29 or day<1:
        day = int(input("Day:"))
        if day<1 or day>29:
            print("Out of allowed range 1 - 29")

Went ahead of myself!

This is the correct solution!

elif month == 14 and (year+1)%400 == 0:
    while day>29 or day<1:
        day = int(input("Day:"))
        if day<1 or day>29:
            print("Out of allowed range 1 - 29")

elif month == 14 and (year+1)%4 == 0 and (year+1)%100 != 0:
    while day>29 or day<1:
        day = int(input("Day:"))
        if day<1 or day>29:
            print("Out of allowed range 1 - 28")
Very thankful for your help!
Reply


Messages In This Thread
RE: Problem with code to calculate weekday for leap years! - by Event - Dec-15-2018, 05:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Frog codility leap sort variant MoreMoney 5 459 Apr-06-2024, 08:47 PM
Last Post: deanhystad
  Calculate AGE in years Kessie1971 17 3,588 Apr-26-2023, 03:36 PM
Last Post: deanhystad
  Tracking leap.py years for gregorian calendar (Exercism org) Drone4four 11 3,841 Oct-14-2022, 03:20 PM
Last Post: betinajessen
  python age calculator need to find the number of years before they turn 100 not using orangevalley 4 10,018 Mar-26-2018, 04:44 AM
Last Post: PyMan
  human years to dog years jhall710 7 11,482 May-08-2017, 05:57 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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