Next Date with Same Weekday
Next Date with Same Weekday
Problem:
Calculate the date of next 7th day from the given date.
Input:
31-03-2019
Output:
07-04-2019
Program:
def leap(y):
return (y%400==0 or (y%4==0 and y%100!=0))
s = list(map(int,input().split("-")))
s[0] += 7
a = [1,3,5,7,8,10,12]
b = [2]
c = [4,6,9,11]
if s[1] in a and s[0] > 31:
s[0] = s[0] % 31
s[1] += 1
if s[1] > 12:
s[1] = s[1]%12
s[2] += 1
if s[1] in c and s[0] > 30:
s[0] = s[0] % 30
s[1] += 1
if s[1] in b:
if leap(s[2]) and s[0] > 29:
s[0] = s[0] % 29
s[1] += 1
elif not(leap(s[2])) and s[0] > 28:
s[0] = s[0] % 28
s[1] += 1
print("%.02d"%s[0],"%.02d"%s[1],"%.02d"%s[2],sep="-")
Comments
Post a Comment