输入某年某月某日,判断这一天是这一年的第几天?(使用python语言)
生活随笔
收集整理的這篇文章主要介紹了
输入某年某月某日,判断这一天是这一年的第几天?(使用python语言)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. import datetime
2. def dayofyear():
3. year = input("請輸入年份:")
4. month = input("請輸入月份:")
5. day = input("請輸入天:")
6. date1 = datetime.date(year=int(year),month=int(month),day=int(day)) #year ,month,day取整
7. date2 = datetime.date(year=int(year),month=1,day=1) #做差
8. return (date1 - date2 + 1).days
總結
以上是生活随笔為你收集整理的输入某年某月某日,判断这一天是这一年的第几天?(使用python语言)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: X-Y PROBLEM
- 下一篇: Django框架实现支付宝第三方支付