把日期翻译成英文表示形式

把用户输入的日期翻译成英文表示形式

添加英文后缀,即添加“第”,1、2、3英文的后缀分别是st、nd、rd,其它则用th代表

如下例子

>>> add_suffix = ('st', 'nd', 'rd') + ('th',) * 17 + ('st', 'nd', 'rd') + ('th',) * 7 + ('st',)
>>> day = input("请输入日期(1-31):")
请输入日期(1-31):24
>>> day_int = int(day)
>>> print(day + add_suffix[day_int - 1])
24th

敲黑板,注意, ('th',)这个写法,‘th' 后加逗号表示只有一个元素‘th’的元组,如果不加 ‘,’逗号,则表示字符串‘th‘。

posted @ 2019-12-25 08:26  土豆笔记  阅读(913)  评论(0编辑  收藏  举报