Python小练习
来源:互联网 发布:解压缩软件密码破解 编辑:程序博客网 时间:2024/06/18 15:43
输入年月日,判断这是今年的多少天
注意:
1.天数 = 上一月为止累计的天数 + 本月天数
2.闰年和非闰年的2月天数要作区分
3.本年为闰年,输入的月份是否大于2也要作判断
year = int(input("请输入年份:"))month = int(input("请输入月份:"))day = int(input("请输入日期:"))months = [0,31,59,90,120,151,181,212,243,273,304] # months累加记录1-11月的总天数if 0 < month < 12: # 假设为非闰年时,当前日期的天数 sum = months[month - 1] + dayflag = 0if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): # 判断是否为闰年,如果为闰年flag = 1 flag = 1if flag == 1 and month > 2: # 年份为闰年且月份大于2 sum += 1print("%d.%d.%d 是 %d 年的第 %d 天" % (year,month,day,year,sum))
输入年月日,判断今年还剩多少天
此程序和上一个程序其实大同小异,只需要知道今年总天数,然后:
今年剩余多少天 = 总天数 - 今天是今年的多少天
你就说简不简单?
year = int(input("请输入年份:"))month = int(input("请输入月份:"))day = int(input("请输入日期:"))days = 365months = [0,31,59,90,120,151,181,212,243,273,304]if 0 < month < 12: sum = months[month - 1] + dayflag = 0if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): flag = 1 days += 1if flag == 1 and month > 2: sum += 1surplus_day = days - sumprint("今天是:%d.%d.%d,今年还剩 %d 天" % (year,month,day,surplus_day))
两个程序可以综合起来,具体步骤就不详细说明了!!!
加油!O(∩_∩)O
阅读全文
0 0
- python小练习
- python小项目练习
- python小练习
- python练习小程序
- python小练习
- Python 小练习_battleship
- Python 小练习 阶乘
- Python-小练习
- Python小练习
- Python小练习一
- Python小练习1
- python练手小练习
- python小练习----秒表
- python第二次小练习
- Python小练习三
- Python小练习
- python小程序练习
- Python练习小案例
- 21 Running and Creating Executables
- @Controler注解未生效报No mapping found for HTTP request with URI 错误
- unity 二维码相关
- vue中引入Moment.js
- Unity UGUI事件系统
- Python小练习
- Echarts x轴字体倾斜
- Python3学习笔记7-文件的读写
- 22 More Libraries
- JavaScript数据类型
- 1. Locust的hack之路- 压测脚本的传输及自启动slaves
- 说说 Java I/O 系统——如何执行操作系统的命令
- 23 Dialects of Racket and Scheme
- Centos 安装ab工具