缩写月份单词
类型:字符串
月份的英文单词及其缩写如下所示:
月份的缩写为月份单词的前3个字母(9月为前4个),且首字母大写,以 '.' 做为缩写结束标记。编写一个程序,用户输入一个月份单词,不论输入的单词各字符是大写还是小写,请正确输出对应月份的缩写。当输入单词拼写错误时,输出“spelling mistake”。
# 提示,字符串有以下方法可用
str.upper() 转换字符串 str 中所有字母为大写
str.lower() 转换字符串 str 中所有字母为小写
str.capitalize() 把字符串 str 的第一个字符大写# 月份名列表
month_lst = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
某月份的英文单词
该月的缩写或“spelling mistake”
输入:february
输出:Feb.
输入:auGust
输出:Aug.
处理输入字符串,首先lower()转换为小写,然后capitalize()转化为首字母大写,之后就是分支判断了。
# 月份的英文单词及其缩写如下所示:
#
# 一月 Jan. January
# 二月 Feb. February
# 三月 Mar. March
# 四月 Apr. April
# 五月 May. May
# 六月 Jun. June
# 七月 Jul. July
# 八月 Aug. August
# 九月 Sept. September
# 十月 Oct. October
# 十一月 Nov. November
# 十二月 Dec. December
# 月份的缩写为月份单词的前3个字母,且首字母大写,以 '.' 做为缩写结束标记。
# 编写一个程序,用户输入一个月份单词,不论输入的单词各字符是大写还是小写,请正确输出对应月份的缩写。
# 当输入单词拼写错误时,输出“spelling mistake”。“拼写错误”# str.upper() 转换字符串str中所有字母为大写
# # str.lower() 转换字符串str中所有字母为小写
# # str.capitalize() 把字符串str的第一个字符大写
# 分支语句实现
month = input().lower().capitalize()
if month == 'January':output = month[:3] + '.'
elif month == 'February':output = month[:3] + '.'
elif month == 'March':output = month[:3] + '.'
elif month == 'April':output = month[:3] + '.'
elif month == 'May':output = month[:3] + '.'
elif month == 'July':output = month[:3] + '.'
elif month == 'July':output = month[:3] + '.'
elif month == 'August':output = month[:3] + '.'
elif month == 'September':output = month[:4] + '.'
elif month == 'October':output = month[:3] + '.'
elif month == 'November':output = month[:3] + '.'
elif month == 'December':output = month[:3] + '.'
else:output = 'spelling mistake'
print(output)# 逻辑表达式实现
month = input().lower().capitalize()
if month == 'September':output = month[:4] + '.'
elif month == 'January' or month == 'February' or month == 'March' or month == 'April' or month == 'May' or month == 'July' or month == 'July' or month == 'August' or month == 'September' or month == 'October' or month == 'November' or month == 'December':output = month[:3] + '.'
else:output = 'spelling mistake'
print(output)# 列表实现
month = input().lower().capitalize()
month_lst = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October','November', 'December']
if month == 'September':print(month[:4] + '.')
elif month in month_lst:print(month[:3] + '.')
else:print('spelling mistake')
本文发布于:2024-01-29 09:27:52,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170649167714314.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |