Sentence = input("Type a sentence")
Loop = True
While loop = True:
If # something to detect punctuati#:
Loop = True
Else:
Loop = False
Run Code Online (Sandbox Code Playgroud)
如果您想要简单的东西,可以punctuation从字符串导入,然后检查字符串是否包含标点符号字符。
from string import punctuation
my_text = 'What?'
>>> any(p in my_text for p in punctuation)
True
Run Code Online (Sandbox Code Playgroud)
例子
while True:
s = raw_input('type a sentence without punctuation: ') # Python 2
if not any(p in s for p in punctuation):
break
Run Code Online (Sandbox Code Playgroud)