【问题标题】:Make every version of "cease" the same - uppercase = lowercase = capitalized first letter = any letter capitalized使“停止”的每个版本都相同 - 大写 = 小写 = 大写的第一个字母 = 任何大写的字母
【发布时间】:2018-02-06 01:06:07
【问题描述】:

我有以下代码。

如何让“停止”一词的所有情况停止程序

基本上我想要停止 = 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)

【问题讨论】:

  • 全部小写还是大写?
  • while UserCity.lower() != 'cease': ...

标签: python python-3.x capitalization


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-29
    • 2011-12-11
    • 1970-01-01
    • 2013-09-01
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多