程序:显示法定格式的日期合同和其他法律文档中经常使用下列日期格式: Dated this day of ,19 . 编写程序用来显示这种格式的日期。用户以月/日的格式录入日期,然后计算机显示出“法定”格式的日期: Enter date (mm/dd/yy) : 7/19/96 Dated this 19th day of July, 1996.
时间: 2023-05-11 11:04:17 浏览: 116
日期的显示格式
5星 · 资源好评率100%
以下是程序的 Python 代码:
month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
suffixes = ["th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"]
date_str = input("Enter date (mm/dd/yy): ")
month, day, year = date_str.split("/")
month = int(month)
day = int(day)
year = int(year)
month_name = month_names[month - 1]
suffix = suffixes[day % 10] if day not in [11, 12, 13] else "th"
print(f"Dated this {day}{suffix} day of {month_name}, {year}.")
阅读全文