months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
'October', 'November', 'December']
#一个列表,其中包含数1~31对应的结尾
endings = ['st', 'nd', 'rd'] + 17 * ['th'] + ['st', 'nd', 'rd'] + 7 * ['th'] + ['st']
year = input("Year:")
month = input("Month(1-12):")
day = input("Day(1-31):")
month_number = int(month)
day_number = int(day)
# 别忘了将表示月和日的数减1,这样才能得到正确的索引
month_name = months[month_number - 1]
ordinal = day + endings[day_number - 1]
print(month_name + ' ' + ordinal + ',' + year)
Python输入输出年月日
最新推荐文章于 2025-09-16 08:29:04 发布
本文介绍了如何使用Python创建一个程序来输出特定日期格式。通过输入年份、月份和日期,程序将返回相应的月份名称和日期缩写。适用于日期处理的基础学习。
1万+

被折叠的 条评论
为什么被折叠?



