马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def judge_year(year):
if year % 4 == 0:
if year % 400 == 0:
year_name = 366 # 'a leap year'
elif year % 100 == 0:
year_name = 365 # 'not a leap year'
else:
year_name = 366 # 'a leap year'
else:
year_name = 365 # 'a leap year'
return year_name
def ordinaldate(year, month, day):
JAN = [1, 31]
MAR = [3, 31]
APR = [4, 30]
MAY = [5, 31]
JUN = [6, 30]
JUL = [7, 31]
AUG = [8, 31]
SEP = [9, 30]
OCT = [10, 31]
NOV = [11, 30]
DEC = [12, 31]
if judge_year(year) == 366:
FEB = [2, 29]
else:
FEB = [2, 28]
if month == JAN[0]:
cumulative_monthly_days = 0
ordinal_date = cumulative_monthly_days + day
elif month == FEB[0]:
cumulative_monthly_days = JAN[1]
ordinal_date = cumulative_monthly_days + day
elif month == MAR[0]:
cumulative_monthly_days = JAN[1] + FEB[1]
ordinal_date = cumulative_monthly_days + day
elif month == APR[0]:
cumulative_monthly_days = JAN[1] + FEB[1] + MAR[1]
ordinal_date = cumulative_monthly_days + day
elif month == MAY[0]:
cumulative_monthly_days = JAN[1] + FEB[1] + MAR[1] + APR[1]
ordinal_date = cumulative_monthly_days + day
elif month == JUN[0]:
cumulative_monthly_days = JAN[1] + FEB[1] + MAR[1] + APR[1] + MAY[1]
ordinal_date = cumulative_monthly_days + day
elif month == JUL[0]:
cumulative_monthly_days = JAN[1] + FEB[1] + MAR[1] + APR[1] + MAY[1] + JUN[1]
ordinal_date = cumulative_monthly_days + day
elif month == AUG[0]:
cumulative_monthly_days = JAN[1] + FEB[1] + MAR[1] + APR[1] + MAY[1] + JUN[1] + JUL[1]
ordinal_date = cumulative_monthly_days + day
elif month == SEP[0]:
cumulative_monthly_days = JAN[1] + FEB[1] + MAR[1] + APR[1] + MAY[1] + JUN[1] + JUL[1] \
+ AUG[1]
ordinal_date = cumulative_monthly_days + day
elif month == OCT[0]:
cumulative_monthly_days = JAN[1] + FEB[1] + MAR[1] + APR[1] + MAY[1] + JUN[1] + JUL[1] \
+ AUG[1] + SEP[1]
ordinal_date = cumulative_monthly_days + day
elif month == NOV[0]:
cumulative_monthly_days = JAN[1] + FEB[1] + MAR[1] + APR[1] + MAY[1] + JUN[1] + JUL[1] \
+ AUG[1] + SEP[1] + OCT[1]
ordinal_date = cumulative_monthly_days + day
elif month == DEC[0]:
cumulative_monthly_days = JAN[1] + FEB[1] + MAR[1] + APR[1] + MAY[1] + JUN[1] + JUL[1] \
+ AUG[1] + SEP[1] + OCT[1] + NOV[1]
ordinal_date = cumulative_monthly_days + day
return ordinal_date
def main():
year = int(input('please enter the year:'))
month = int(input('please enter the month:'))
day = int(input('please enter the day:'))
print('The ordinal date is', ordinaldate(year, month, day))
if __name__ == '__main__':
main()
在这里的第73行,在pycharm里面一直让我添加global条件,添加之后报错,不添加程序正常运行,只是显示一个warning,这个怎么解决?怎么解释?
|