使用true和false语句在python中循环整个程序 [英] Looping a whole program in python using true and false statements

查看:137
本文介绍了使用true和false语句在python中循环整个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个程序,但是我不知道如何循环它.帮助将不胜感激. 这是我需要帮助的程序.

I have written a program but I do not know how to loop it. Help would be appreciated. Here is the program I need help with.

推荐答案

有两种类型的循环:不定式(while)循环和定式(for)循环.如果要循环执行程序特定的次数,请使用for循环:

There are two types of loops: indefinite (while) loops and definite (for) loops. If you want to loop your program a specific amount of times, then use the for loop:

for count in range(0, <number of repetitions minus one>):
    # code

如果要在用户输入"QUIT"或其他字符串之前循环执行程序,请使用以下方法:

If you want to loop the program until the user enters "QUIT" or some other string, use this:

sentinel = input("Enter QUIT to exit or anything else to continue: ")
while sentinel.upper() != "QUIT":
    # code

以下是一些有用的教程链接:

Here are some helpful links to tutorials:

http://www.learnpython.org/en/Loops

http://www.python-course.eu/python3_for_loop.php

http://anh. cs.luc.edu/python/hands-on/3.1/handsonHtml/whilestatements.html#while-statements

这篇关于使用true和false语句在python中循环整个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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