計算某天是一年的第幾天

2021-09-25 07:43:37 字數 875 閱讀 9750

大致思路

輸入年月日:獲取1月1號到上個月月末的天數 加上輸入的日期值

注意:閏年且輸入月份大於3時需考慮多加一天

year = input('year:\n')

month = input('month:\n')

day = input('day:\n')

months = (0,31,59,90,120,151,181,212,243,273,304,334) #0~12個月的天數

if 0 < month <= 12:

sum = months[month - 1]

else:

print('month error')

sum += day

leap = 0

if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)): #算閏年

ryear = 1

if (ryear == 1) and (month > 2):

sum += 1

print( 'it is the %dth day.' % sum)

閏年

公曆年份是整百或整千的(也就是年份末尾至少有2個0的),用年份除以400,如果能整除,就是閏年,不能整除就是平年,

公曆其他的年份,用年份除以4,如果能整除,就是閏年,不能整除就是平年,

如2023年,1900÷400=4……300 就是平年,平年2月是28天.

2023年,2000÷400=5 就是閏年,閏年2月是29天.

2023年,2002÷4=500……2就是平年

2023年,2004÷4=501 就是閏年

閏年2月是29天 平年2月是28天.

工資計算問題,類似計算某天是一年中的第幾天的問題

企業發放的獎金根據利潤提成。利潤i 低於或者等於 10萬元時,獎金可提成 10 利潤高於 10萬元且低於 20萬元時,其中 10萬元按 10 提成,高於 10萬元的部分,可提成 7.5 200000時,其中 20萬仍按上述辦法提成 下同 高於 20萬的部分按 5 提成 400000時,高於 40萬部...

工資計算問題,類似計算某天是一年中的第幾天的問題

企業發放的獎金根據利潤提成。利潤i低於或者等於10萬元時,獎金可提成10 利潤高於10萬元且低於20萬元時,其中10萬元按10 提成,高於10萬元的部分,可提成7.5 2000001000000時,超過100萬的部分按1 提成。從鍵盤輸入當月利潤i,求出應發放獎金總數。要求 用if語句和switch...

計算某天在當年是第幾天

1.先貼我自己的 1 include2 include3 4int main date 11int num 0 12 inttue 13date date 1415 printf input the date n 16 scanf d d d date.year,date.month,date.da...