print("Enter as many lines of text as you want.")
print("When you're done, enter a single period on a line by itself.")
buffer = []
while True:
print("> ", end="")
line = input()
if line == ".":
break
buffer.append(line)
multiline_string = "\n".join(buffer)
print("You entered...")
print()
print(multiline_string)
def processString(x):
print(x.replace('process','whatever'))
lines = ""
while True:
if lines == "":
lines = ""
print("Enter string:")
x = input()
if x == "" and lines != "":
processString(lines)
break
else:
lines += x
# then hit enter once after multi-line string to process it
在程序中这样做的一种常见方法是有一个“I'm done”字符串(例如,一个句点),并保持逐行读取,直到读取的行与该字符串匹配为止。
你可以使用sys库
相关问题 更多 >
编程相关推荐