English 中文(简体)
在休息时间结束时没有“破碎”会导致有限的休息?
原标题:When would the absence of "break" at the end of a while loop lead to infinite loops?

我建立了sil默功能,看看看是否有数字。

def check_digit_placement(w):
    if w.isalpha():
        return True
    else:
        i=0
        while True:
            if w[i].isdigit():
                return True    #Would the absence of "break" here lead to an infinite while loop?
            else:
                return False    #And here too.

            i+=1

        if i>len(w):
            break

这一职能行之有效,但正如上述评论所示,我仍然很关切:如果没有适当的休息, lo是否在某个时候被 st,回到“True”或“False”? 如果是的话,那么为什么职能似乎发挥作用? 任何帮助都将受到高度赞赏。

问题回答

我认为,现在应该把法典改变为这一条。

i=0
while i < len(w):
    if w[i].isdigit():
        return True
    i+=1
return False

因为你的职能只是首先检查,而不是数字。

你有权利感到关切。 如果没有列入“突破性”声明,则你实际上会变成无限的 lo,从而防止职能按预期运作。 视第一种特性是否为数,该方位代表要么在一开始就返回真实或合法。 这一职能现在将恢复价值,因此永远不会达到“i+=1”声明。

def check_digit_placement(w):
    if w.isalpha():
        return True
    else:
        i = 0
        while i < len(w):
            if w[i].isdigit():
                return True
            else:
                i += 1
        return False




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签