【问题描述】
输出给定月份数字对应的月份名称缩写。
要求:输入一个表示月份的数字(1~12),输出其对应月份名称的缩写
举例:输入3,程序输出Mar.
方法:利用字符串剪切操作来实现该功能
将所有的月份名称储存在一个字符串中:
months = “JanFebMarAprMayJunJulAugSepOctNovDec”
在字符串中截取适当的子串来实现特定月份的查找
问题的关键:找出在哪里剪切,例如已经算出在pos处开始,那么每个月的缩写都由3个字母组成,需要获得从起始位置pos开始且长度为3的子串:
monthAbbrev = months[pos:pos+3]
【输入形式】
【输出形式】
【样例输入输出】
Enter a month number (1-12):3
The month abbreviation is Mar.
【样例说明】
【评分标准】
a=eval(input("Enter a month number (1-12):"))
suoxie="JanFebMarAprMayJunJulAugSepOctNovDec"
b=(a-1) * 3
c=suoxie[b:b + 3]
print("The month abbreviation is",c+".")