如何重复或停止
How to repeat or stop
我正在尝试制作一个询问文本的程序,然后根据需要重复它 x 次。我希望它在完成前面的文本时总是询问您,如果您键入 "Stop" 它将结束程序。到目前为止我已经这样做了:
text = input("Give a text: ")
times = int(input("Give a number: "))
for i in range(0, times):
print(text)
一个例子:
Give a text: Wadap
Give a number: 3
Wadap
Wadap
Wadap
Give a text: Hi
Give a number: 2
Hi
Hi
Give a text: Stop
Stopping.
您想将所有内容包装在 while
循环中。
some_condition = True
while some_condition:
<your code>
这里some_condition
只是一个你可以控制退出程序的变量
您需要将现有代码放入 while
循环中:
text = input("Give a text: ")
while text != "Stop":
times = int(input("Give a number: "))
for i in range(0, times):
print(text)
text = input("Give a text: ")
print("Stopping")
我正在尝试制作一个询问文本的程序,然后根据需要重复它 x 次。我希望它在完成前面的文本时总是询问您,如果您键入 "Stop" 它将结束程序。到目前为止我已经这样做了:
text = input("Give a text: ")
times = int(input("Give a number: "))
for i in range(0, times):
print(text)
一个例子:
Give a text: Wadap
Give a number: 3
Wadap
Wadap
Wadap
Give a text: Hi
Give a number: 2
Hi
Hi
Give a text: Stop
Stopping.
您想将所有内容包装在 while
循环中。
some_condition = True
while some_condition:
<your code>
这里some_condition
只是一个你可以控制退出程序的变量
您需要将现有代码放入 while
循环中:
text = input("Give a text: ")
while text != "Stop":
times = int(input("Give a number: "))
for i in range(0, times):
print(text)
text = input("Give a text: ")
print("Stopping")