根据问题中的代码,它只接受一行输入。您需要多次编写整个代码块,或者可以利用
循环
具有
while
在python中。
例如,您可以一步一步地执行以下过程:
-
设置循环并使其无限,除非它收到
quit
-
将整个代码块放入循环中(
while True
)街区。
-
添加停止条件,即当接收到
quit 0
.
以下是上述步骤的代码。
while True: # Make an infinite loop.
# Put the whole block to make sure it repeats
makeList = UserEntered.split()
get_item_1 = makeList[slice(0,1)][0]
get_item_2 = makeList[slice(1,2)][0]
# Print when the input is not `quit 0`
if "quit" not in makeList:
print("Eating {} {} a day keeps the doctor away.".format(get_item_2,get_item_1))
# Stopping control/condition here, when it receives `quit 0`
else:
break