如何在Python3.4.2上循环? [英] How to loop on Python 3.4.2?
本文介绍了如何在Python3.4.2上循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的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?
推荐答案
我想这就是您要找的东西:
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'))
为真。
这篇关于如何在Python3.4.2上循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文