使 "cease" 的每个版本都相同 - 大写 = 小写 = 首字母大写 = 任何字母大写

Make every version of "cease" the same - uppercase = lowercase = capitalized first letter = any letter capitalized

我有下面的代码。

我如何让单词 "cease" 的所有大小写停止程序

基本上我想要 cease = Cease = CEASE = ceaSe = cEasE 等等

有什么想法吗?

Cities = []
UserCity = ''

while UserCity != 'cease':
    UserCity = input("Enter city = ")

    if UserCity != 'cease':
        Cities.append(UserCity)

print("\n" + 'Cities listed are: ')
for item in Cities:
    print(item)

为了节省大量时间,您可以将 UserCity 转换为小写,这样您就不必检查每个可能的停止组合。正如 Joran Beasley 所说,这可以很容易地完成:

while UserCity.lower() != "cease":

对于另一个 if 语句,可以通过以下方式完成:

if UserCity.lower() != "cease":