Re: exiting a while loop

2020-05-23 Thread Grant Edwards
On 2020-05-22, DL Neil via Python-list wrote: > On 23/05/20 4:31 AM, Grant Edwards wrote: >> On 2020-05-22, Peter Otten <__pete...@web.de> wrote: >> >>> If you want to terminate the script you can use exit. However exit >>> is a function, and you have to call it >>> >>> exit() >> >> >> >> Actu

Re: exiting a while loop

2020-05-23 Thread Terry Reedy
On 5/22/2020 12:31 PM, Grant Edwards wrote: On 2020-05-22, Peter Otten <__pete...@web.de> wrote: If you want to terminate the script you can use exit. However exit is a function, and you have to call it exit() Actually it's an instance of _sitebuiltins.Quitter not a function. Which means

Re: exiting a while loop

2020-05-22 Thread DL Neil via Python-list
On 23/05/20 4:31 AM, Grant Edwards wrote: On 2020-05-22, Peter Otten <__pete...@web.de> wrote: If you want to terminate the script you can use exit. However exit is a function, and you have to call it exit() Actually it's an instance of _sitebuiltins.Quitter not a function. You still have

Re: exiting a while loop

2020-05-22 Thread Grant Edwards
On 2020-05-22, Peter Otten <__pete...@web.de> wrote: > If you want to terminate the script you can use exit. However exit > is a function, and you have to call it > > exit() Actually it's an instance of _sitebuiltins.Quitter not a function. You still have to call it. ;) -- Grant -- https:

Re: exiting a while loop

2020-05-22 Thread D'Arcy Cain
On 2020-05-22 7:49 a.m., John Yeadon via Python-list wrote: > Am I unreasonable in expecting this code to exit when required? Yes. > # Add up the powers of 2 starting with 2**0 until 2 million is met. > n = 1 > target = 200 > sum = 0 > > while True: >     x = 2 ** (n - 1) >     sum += x >   

Re: exiting a while loop

2020-05-22 Thread Dan Sommers
On Friday, May 22, 2020, at 7:49, John Yeadon via Python-list wrote: > Am I unreasonable in expecting this code to exit when required? Yes. :-) > # Add up the powers of 2 starting with 2**0 until 2 million is met. > n = 1 > target = 200 > sum = 0 > > while True: > x = 2 ** (n - 1) >

Re: exiting a while loop

2020-05-22 Thread Peter Otten
John Yeadon via Python-list wrote: > Am I unreasonable in expecting this code to exit when required? It is unreasonable to expect something that doesn't match what you read in the tutorial ;) If you want to terminate the script you can use exit. However exit is a function, and you have to call

Re: exiting a while loop

2020-05-22 Thread Souvik Dutta
No not really. If you use a breakpoint and a debugger you will find out that your code continues till 2 M is met and then stops printing numbers continuously. On Fri, 22 May, 2020, 5:20 pm John Yeadon via Python-list, < python-list@python.org> wrote: > Am I unreasonable in expecting this code to

Re: exiting a while loop

2020-05-22 Thread Larry Martell
On Fri, May 22, 2020 at 7:51 AM John Yeadon via Python-list wrote: > > Am I unreasonable in expecting this code to exit when required? > > > # Add up the powers of 2 starting with 2**0 until 2 million is met. > n = 1 > target = 200 > sum = 0 > > while True: > x = 2 ** (n - 1) > sum +