python - check at the end of the loop if need to run again

前端 未结 4 1879
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 18:20

It\'s a really basic question but i can\'t think at the second. How do i set up a loop that asks each time the function inside runs whether to do it again. So it runs it then sa

4条回答
  •  感情败类
    2021-01-21 18:42

    keepLooping = True
    while keepLooping:
      # do stuff here
    
      # Prompt the user to continue
      q = raw_input("Keep looping? [yn]: ")
      if not q.startswith("y"):
        keepLooping = False
    

提交回复
热议问题