如何在Python3.4.2上循环?如何在

由网友(假烟假酒假朋友)分享简介:在我的Python代码中,我有一个部分,如果问题与我想要的不匹配,我想重复打印它。name1 = input("A male name (protagonist): ")if name1.endswith (('ly', 's')):print("Sorry mate, this doesn't seem to be...

在我的Python代码中,我有一个部分,如果问题与我想要的不匹配,我想重复打印它。

name1 = input("A male name (protagonist): ")
    if name1.endswith (('ly', 's')):
        print("Sorry mate, this doesn't seem to be a proper noun. Try it again.")
        name1 = input("A male name (protagonist): ")

如果以"ly"或"s"结尾,如何使其重复打印出name1?

推荐答案

关于在Python的for循环中改变列表的值问题探究

我想这就是您要找的东西:

while True:
    name1 = input("A male name (protagonist): ")
    if name1.endswith(('ly', 's')):
        print("Sorry mate, this doesn't seem to be a proper noun. Try it again.")
        continue
    break

print("Input name is:", name1)  

这将循环执行,直到if name1.endswith(('ly', 's'))为真。

阅读全文

相关推荐

最新文章