python-在循环结束时检查是否需要再次运行 [英] python - check at the end of the loop if need to run again

查看:121
本文介绍了python-在循环结束时检查是否需要再次运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常基本的问题,但我第二想不起来.我如何设置一个循环,每次内部函数运行时都询问是否再次执行该循环.因此它运行,然后说类似的内容;

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 says something like;

再次循环播放?是/否"

"loop again? y/n"

推荐答案

while True:
    func()
    answer = raw_input( "Loop again? " )
    if answer != 'y':
        break

这篇关于python-在循环结束时检查是否需要再次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆