[Tutor] Python problem
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Feb 27 06:33:49 EST 2021
On 27/02/2021 11:19, Alan Gauld via Tutor wrote:
> On 27/02/2021 07:23, Vakhtang Kvaratskhelia wrote:
>
>> What i mean is that if i write the code (for simplicity i have
>> precalculated variables mentioned in the previous emails and narrowed the
>> code down to the following ) :
>
> I'm confused. I'd expect both versions to give an infinite loop since
> you never change portion_saved and it is equal to zero. So the while
> loop will always evaluate to the same result.
OOPS! I just spotted that you do in fact modify the portion_saved.
Ignore that.
But i'm still confused about how the commas are working. If someone with
a comma sensitive locale could explain I'd be interested.
>> low=0
>> high=10000
>> epsilon=100
>> portion_saved=0
>> while abs(250,000 - portion_saved * 566,774) >= epsilon:
>> if portion_saved * 566,774 < 250,000 :
>> low=portion_saved
>> else:
>> high=portion_saved
>> portion_saved=(high+low) // 2
Sorry, I missed that line somehow!
>> print(portion_saved)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list