Python 缩写月份单词

#注:
str.capitalize() 把字符串str的第一个字符大写

#1:

x=input().lower()

ls=["january","february","march","april","may","june",
"july","august","september","october","November","December"]

if x not in ls:
    print("spelling mistake")
else:
    y=x[0].upper()
    t=y+x[1:3]+'.'
    print(t)

#2:

x=input().lower().capitalize()

ls=['January', 'February', 'March', 'April', 'May',
    'June', 'July', 'August', 'September', 'October',
    'November', 'December']

if x not in ls:
    print("spelling mistake")
else:
    t=x[:3]+'.'
    print(t)

你可能感兴趣的:(Python)