如何让 raw_input 重复直到我想退出? [英] How to let a raw_input repeat until I want to quit?
本文介绍了如何让 raw_input 重复直到我想退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我想像这样使用 raw_input
:
code = raw_input("请输入您的三字母代码或空行退出:")
下:
if __name__=="__main__":
如何让它重复多次而不是每次运行程序时只重复一次?
另一个问题是写什么代码可以满足条件或空行退出(程序)".
How can I let it repeat multiple times rather than just once every time I run the program?
Another question is to write what code can satisfy the condition "or a blank line to quit (the program)".
推荐答案
best:
if __name__ == '__main__':
while True:
entered = raw_input("Please enter your three-letter code or leave a blank line to quit: ")
if not entered: break
if len(entered) != 3:
print "%r is NOT three letters, it's %d" % (entered, len(entered))
continue
if not entered.isalpha():
print "%r are NOT all letters -- please enter exactly three letters, nothing else!"
continue
process(entered)
这篇关于如何让 raw_input 重复直到我想退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文