python根据给定的年月日以数字形式打印日期
来源:互联网 发布:java测试工程师 编辑:程序博客网 时间:2024/05/01 15:56
months=['January','February','March','April','May','June','July','August','September','October','November','December']
以1-31的数字作为结尾的列表,定义的endings变量赋值后面加上17*和7*,
原来该变量定义的是1-31这31个数的英文后缀,这31个数的英文是1:first 2:second 3:third
4:fourth 5:fifth 6:sixth 7:seventh 8:eighth 9:ninth 10:tenth 11:eleventh 12:twelfth 13:thirteenth 14:fourteenth 15:fifteenth
16:sixteenth 17:seventeenth 18:eighteenth 19:ninteenth 20:twentieth21:twentyfirst 22:twenty-second 23:twenty-third24:twenty-fourth 25:twenty-fifth 26:twenty-sixth 27;twenty-seventh 28:twenty-eighth 29:twenty-ninth 30:thirtieth 31:thirty-first
其中在第一个 [‘st’,’nd’,’rd’]后面从fourth到twentieth一共是17个‘th’,然后是又一个[‘st’,’nd’,’rd’]后面再从twenty-fourth到thirtieth一共是7个‘th’,17 * [‘th’]的意思就是:给这个数据添加17个’th’字符串
endings=['st','nd','rd']+17*['th']\ +['st','nd','rd']+7*['th']\ +['st']
获取用户输入的日期信息
year =raw_input('Year: ')month =raw_input('Month(1-12): ')day =raw_input('Day(1-31): ')
将月份和日期转化成整数
month_number=int(month)day_number=int(day)
因为索引从0开始所以取到的月份和天数会往后推一个月,获取当前的日期需要减一 ,例如:输入month_name 3 ,取到的是April四月,实际上我们想要的是三月
month_name=months[month_number-1]ordinal=day+endings[day_number-1]
打印日期
print month_name+' '+ordinal+'.'+year
- python根据给定的年月日以数字形式打印日期
- php根据给定日期获取给定日期本周的日期
- 根据日期(年月日)得到星期几的方法
- 根据输入的年月日,自动判断生日日期
- java 根据给定的日期得到给定日期的前一天的日期
- 利用python读取文件 然后以表格的形式打印出去
- 给定一个数字,怎么判断它是不是回文形式的?
- 根据数字打印对应的图案
- 问题:计算给定年月日的日期是星期几(泽勒一致性)
- python 打印数值的二进制形式
- 根据年月日得到日期是星期几
- 根据年月日得到日期是星期几
- sql 根据年月日得到日期列
- 使用shell实现打印给定日期的日历
- C和指针之函数之归以字符形式按顺序打印数字的每位数字(递归和非递归)
- 质数-C++代码-打印给定数字内的质数
- 以每行一个单词的形式打印输入
- 以表格的形式打印出MySQL数据库中表内容.
- 使用IJG JPEG库
- Dispatch相关知识
- 第十三周项目3--Dijkstra算法的验证
- 第14周 项目1-验证算法
- Tomcat6内存溢出问题解决
- python根据给定的年月日以数字形式打印日期
- 常用win+r运行命令总结
- 第十四周项目1-验证算法(1)-折半查找算法
- Spring配置项<context:annotation-config/>解释说明
- 第十三周项目1-Prim算法的验证
- Mybatis--表关联one-to-one
- 用顺序表实现的简易通讯录(第一版)
- Android自定义控件-彩虹条进度条
- Distributed Representations of Words and Phrasesand their Compositionality