循环不起作用

时间:2018-07-22 15:32:15

标签: python

我正在用Python编写一个简单的程序。首先,用户输入一些数据。如果数据等于“ y”,则循环开始

ans = raw_input()
if ans.lower() == 'y':
      for path in mas[]:
           print("This is cycle")
           function()
      print("End of program")

问题在于终端仅输出“程序结束”。循环中的函数或文本输出都不起作用。

1 个答案:

答案 0 :(得分:0)

这很容易,您可以这样做:

while True:
    cont = raw_input("Another one? yes/no > ")
    if cont == "no":
        print("End of program")
        break
    if cont == "yes":
        print("This is cycle")

如果您使用Python3,请将raw_input更改为input

相关问题