循环不存在n

2024-04-20 04:06:07 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

问题是终端只输出“程序结束”。循环中的函数和文本输出都不起作用。你知道吗


Tags: 数据path用户in程序forinputraw
1条回答
网友
1楼 · 发布于 2024-04-20 04:06:07

很简单,你可以这样做:

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。你知道吗

相关问题 更多 >