2023年快手筆試 今年第幾天(python版)

2021-09-26 13:37:51 字數 713 閱讀 8847

方法一:

1、思路:使用python自帶的模組datetime進行計算

2、**:

# coding:utf-8;

import datetime

dtime = list(map(int, input().split()))

doy = datetime.datetime(dtime[0], dtime[1], dtime[2])

# print(type(doy))

print(int(doy.strftime("%j")))

3、輸出結果:

方法二:判斷當前是否是閏年

判斷閏年的方法:(1)能被4整除且不能被100整除的為閏年;(2)能被400整除的是閏年。

year, month, day = map(int, input().split())

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

s = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

else:

s = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

print(sum(s[:month-1]) + day)

016快手 今年的第幾天

問題描述 輸入年 月 日,計算該天是本年的第幾天。輸入 包括三個整數年 1 y 3000 月 1 m 12 日 1 d 31 輸出 輸入可能有多組測試資料,對於每一組測試資料,輸出乙個整數,代表input中的年 月 日對應本年的第幾天。示例輸入 2000 51示例輸出 122思路 判斷是否閏年,累加...

PYTHON輸出今年的第幾天

y eval input 請輸入年份 m eval input 請輸入月份 d eval input 請輸入天數 f true true代表閏年 if y 4 0 and y 100 0 f true elif y 400 00 f true else f false 判斷是否為閏年還是平年 if ...

Python程式設計判斷這天是這一年第幾天的方法示例

本文例項講述了python程式設計判斷這天是這一年第幾天的方法。分享給大家供大家參考,具體如下 題目 輸入某年某月某日,判斷這一天是這一年的第幾天?實現 year int input 請輸入年 month int input 請輸入月 day int input 請輸入天 sum day days ...