网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

Python判断某一天是这一年的第几天

时间:2024-10-13 00:20:19

1、打开桌面的pycharm程序;

Python判断某一天是这一年的第几天

3、依次点击 New > Python File新建一个python文件;

Python判断某一天是这一年的第几天

5、如图示输入如下代码:year = int(input('year:\n'))month = int(input('罪焐芡拂month:\n'))day = int(input('day:\n'))months = (0,31,59,90,120,151,181,212,243,273,304,334)if 0 <= month <= 12: sum = months[month - 1]else: print ('data error')sum += dayleap = 0if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)): leap = 1if (leap == 1) and (month > 2): sum += 1print ('it is the %dth day.' % sum)

6、将鼠标移动至该代码的标签页并右键找到如图示选项:

Python判断某一天是这一年的第几天
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com