Re: Help with Iteration

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Wertman

    Re: Help with Iteration

    >Aaron Brady <cast...pigmail .comwrote:
    >>
    >>while 1:
    >> calculate_stuff ( )
    >> if stuff < 0.00005:
    >> break
    >>
    >The thought police will come and get you.
    Based on Aaron's previous posting history, I suspect this was a joke.
  • Aaron Brady

    #2
    Re: Help with Iteration

    On Oct 19, 12:27 pm, "Eric Wertman" <ewert...@gmail .comwrote:
    Aaron Brady <cast...pigmail .comwrote:
    >
    >while 1:
    >   calculate_stuff ( )
    >   if stuff < 0.00005:
    >       break
    >
    The thought police will come and get you.
    >
    Based on Aaron's previous posting history,  I suspect this was a joke.
    Not necessarily, (technically... ) if you mean that those 4 lines would
    never be consistent with my other stuff, see below. I didn't intend
    to mock the OP at all. But you're right, it definitely looked
    oversimplified.

    'calculate_stuf f' could have been defined local to the function:

    def f():
    stuff= [1]
    def calculate_stuff ( ):
    stuff.append( stuff[-1]* 2 )
    calculate_stuff ( )

    Then the test 'if some_comparison ( stuff )' still makes sense and
    doesn't require a global variable.

    For the 'stuff < 0.00005' test in particular to make sense, 'stuff'
    could be an instance of an object with '__lt__' defined.

    Since Python doesn't define an 'until' statement in addition to
    'while', the question could have been about control flow.

    Comment

    Working...