python 确定天数&比较大小

本文探讨了如何在Python中进行日期的比较和计算,包括使用内置函数进行日期的添加和排序,以及在处理日期时的多重条件判断。通过示例介绍了append()方法添加日期到列表,以及sort()方法对日期列表进行排序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#确定为第几天
year = int(input("请输入年:"))
month = int(input("请输入月:"))
day = int(input("请输入日:"))

months = (0,31,59,90,120,151,181,212,243,273,304,334)

if (year > 0)and(0 < month <= 12)and(0 < day <= 31):
    date = months[month - 1]
    date += day
    i = 0
    if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
        i = 1
    if (i == 1) and (month > 2):
        date += 1
    print(" %d 年 %d 月 %d 日是 %d 年的第 %d 天" % (year,month,day,year,date))
else:
    print("日期输入错误")

#比较大小
list = []
n = int(input("请输入要比较数字的个数:"))
for i in range(n):
    m = int(input("请输入第%d个数字:"%(i+1)))
    list.append(m)
list.sort()
print(list)

多重判断
append(),列表添加数据
sort(),列表排序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

羽黯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值