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

添加英文后缀,即添加“第”,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‘。

相关文章:

  • 2021-09-07
  • 2021-10-30
  • 2021-11-26
  • 2022-12-23
  • 2021-08-06
  • 2021-10-02
  • 2022-12-23
  • 2019-05-15
猜你喜欢
  • 2022-01-23
  • 2021-05-31
  • 2021-07-01
  • 2021-08-02
  • 2021-11-29
相关资源
相似解决方案