Third round of the Smart Iterator Challenge: September-October 2022

2022-10-20 Thread dn
Challenge-week 3: Generalising the solution, starts today! Details from the Meetup site: https://www.meetup.com/nzpug-auckland/events/288813734/ A virtual event run by the Auckland Branch of the New Zealand Python Users' Group. It's Week 3 of the Smart Iterator Challenge! Time to see how modu

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-23 Thread Chris Angelico
On Wed, Nov 24, 2021 at 3:04 AM ast wrote: > > Le 19/11/2021 à 21:17, Chris Angelico a écrit : > > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: > >> > >> Le 19/11/2021 à 03:51, MRAB a écrit : > >>> On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: > On 2021-11-18 at 23:16:32 -0300

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-23 Thread ast
Le 19/11/2021 à 21:17, Chris Angelico a écrit : On Sat, Nov 20, 2021 at 5:08 AM ast wrote: Le 19/11/2021 à 03:51, MRAB a écrit : On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: >>> 0.3 + 0.3 + 0.3 == 0.9 False

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Greg Ewing
On 22/11/21 4:58 am, Grant Edwards wrote: Yep, IIRC, it was a 4 bit processor because 4 bits is what it takes to represent one decimal digit. That was the Saturn, first used in the HP-71B. The original architecture (known as the "Nut")was weirder than that. It operated serially on 56 bit words

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-22 05:43:48 +1100, Chris Angelico wrote: > On Mon, Nov 22, 2021 at 5:42 AM Peter J. Holzer wrote: > > (I think I used Math::BigRat in Perl, but I've been > > programming in Perl for a lot longer.) > > Rodents Of Unusual Size? I don't think they exist... https://www.girlgeniusonline.co

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-21 10:57:55 +1100, Chris Angelico wrote: > And if decimal floating point were common, other "surprise" behaviour > would be cited, like how x < y and (x+y)/2 < x. Yup. Took me a bit to find an example, but this can happen. My HP-48 calculator uses a mantissa of 12 decimal digits. 6

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Chris Angelico
On Mon, Nov 22, 2021 at 5:42 AM Peter J. Holzer wrote: > (I think I used Math::BigRat in Perl, but I've been > programming in Perl for a lot longer.) > Rodents Of Unusual Size? I don't think they exist... ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-20 03:25:53 +, Ben Bacarisse wrote: > Chris Angelico writes: > > > It does mean exactly what it meant in grade school, just as 1/3 means > > exactly what it meant in grade school. Now try to represent 1/3 on a > > blackboard, as a decimal fraction. If that's impossible, does it mea

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-19 12:43:07 +0100, ast wrote: > Le 19/11/2021 à 03:51, MRAB a écrit : > > On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: > > > On 2021-11-18 at 23:16:32 -0300, > > > René Silva Valdés wrote: > > > > Hello, I would like to report the following issue: > > > > > > > > Work

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Grant Edwards
On 2021-11-21, Greg Ewing wrote: > On 21/11/21 2:18 pm, Grant Edwards wrote: >> My recollection is that it was quite common back in the days before FP >> hardware was "a thing" on small computers. CPM and DOS compilers for >> various languages often gave the user a choice between binary FP and >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Greg Ewing
On 21/11/21 2:18 pm, Grant Edwards wrote: My recollection is that it was quite common back in the days before FP hardware was "a thing" on small computers. CPM and DOS compilers for various languages often gave the user a choice between binary FP and decimal (BCD) FP. It's also very common for

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
- From: Python-list On Behalf Of Chris Angelico Sent: Saturday, November 20, 2021 8:03 PM To: python-list@python.org Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding) On Sun, Nov 21, 2021 at 11:39 AM Avi Gross via Python-list wrote: > > Can I suggest a

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 1:20 PM Rob Cliffe via Python-list wrote: > > > > On 21/11/2021 01:02, Chris Angelico wrote: > > > > If you have a number with a finite binary representation, you can > > guarantee that it can be represented finitely in decimal too. > > Infinitely repeating expansions come

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
at each stage continues to generate representable numbers, such as one of the hill climbing algorithms I am talking about. It may end up overshooting a bit past the peak and next round overshooting back to the other side and getting stuck in a loop. One way out is to keep track of past locations and

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Rob Cliffe via Python-list
On 21/11/2021 01:02, Chris Angelico wrote: If you have a number with a finite binary representation, you can guarantee that it can be represented finitely in decimal too. Infinitely repeating expansions come from denominators that are coprime with the numeric base. Not quite, e.g. 1/14 is

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 12:56 PM Avi Gross via Python-list wrote: > > Not at all, Robb. I am not intending to demean Mathematicians as one of my > degrees is in that subject and I liked it. I mean that some things in > mathematics are not as intuitive to people when they first encounter them, >

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
not expected to apply for a non-abelian case. -Original Message- From: Python-list On Behalf Of Rob Cliffe via Python-list Sent: Saturday, November 20, 2021 6:19 PM To: Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding) On 20/11/2021 22:59, Avi Gross

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Grant Edwards
On 2021-11-21, Chris Angelico wrote: >> I think there have been attempts to use a decimal representation in some >> accounting packages or database applications that allow any decimal numbers >> to be faithfully represented and used in calculations. Generally this is not >> a very efficient proce

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 11:39 AM Avi Gross via Python-list wrote: > > Can I suggest a way to look at it, Grant? > > In base 10, we represent all numbers as the (possibly infinite) sum of ten > raised to some integral power. Not infinite. If you allow an infinite sequence of digits, you create num

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
om: Python-list On Behalf Of Grant Edwards Sent: Saturday, November 20, 2021 5:24 PM To: python-list@python.org Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding) On 2021-11-20, Ben Bacarisse wrote: > You seem to be agreeing with me. It's the floating

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 10:55 AM Ben Bacarisse wrote: > > Grant Edwards writes: > > > On 2021-11-20, Ben Bacarisse wrote: > > > >> You seem to be agreeing with me. It's the floating point part that is > >> the issue, not the base itself. > > > > No, it's the base. Floating point can't represent

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Ben Bacarisse
Grant Edwards writes: > On 2021-11-20, Ben Bacarisse wrote: > >> You seem to be agreeing with me. It's the floating point part that is >> the issue, not the base itself. > > No, it's the base. Floating point can't represent 3/10 _because_ it's > base 2 floating point. Floating point in base 10

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
y well be 189.8 but if > I add a feather or subtract one, the reading may well shift to one unit up > or down. Heck, the same person measured just minutes later may shift. If I > used a deluxe scale that measures to more decimal places, it may get hard to > get the exact same number twice

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Rob Cliffe via Python-list
On 20/11/2021 22:59, Avi Gross via Python-list wrote: there are grey lines along the way where some mathematical proofs do weird things like IGNORE parts of a calculation by suggesting they are going to zero much faster than other parts and then wave a mathematical wand about what happens when

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
s just taking a deeper breath may make a change. So what happens if I measure a box in three dimensions to the nearest .1 inch and decide it is 10.1 by 20.2 by 30.3 inches? What is the volume, ignoring pesky details about the width of the cardboard or whatever? A straightforward multiplication yie

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 9:22 AM Grant Edwards wrote: > > On 2021-11-20, Chris Angelico wrote: > > > But you learn that it isn't the same as 1/3. That's my point. You > > already understand that it is *impossible* to write out 1/3 in > > decimal. Is it such a stretch to discover that you cannot wr

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Grant Edwards
On 2021-11-20, Ben Bacarisse wrote: > You seem to be agreeing with me. It's the floating point part that is > the issue, not the base itself. No, it's the base. Floating point can't represent 3/10 _because_ it's base 2 floating point. Floating point in base 10 doesn't have any problem represent

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Grant Edwards
On 2021-11-20, Chris Angelico wrote: > But you learn that it isn't the same as 1/3. That's my point. You > already understand that it is *impossible* to write out 1/3 in > decimal. Is it such a stretch to discover that you cannot write 3/10 > in binary? For many people, it seems to be. There ar

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 8:32 AM Avi Gross via Python-list wrote: > > This discussion gets tiresome for some. > > Mathematics is a pristine world that is NOT the real world. It handles > near-infinities fairly gracefully but many things in the real world break > down because our reality is not infi

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 6:51 AM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 3:41 PM Ben Bacarisse wrote: > >> > >> Chris Angelico writes: > >> > >> > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse > >> > wrote: > >> >> > >> >> Chris Angelico writes: > >> >>

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
This discussion gets tiresome for some. Mathematics is a pristine world that is NOT the real world. It handles near-infinities fairly gracefully but many things in the real world break down because our reality is not infinitely divisible and some parts are neither contiguous nor fixed but in some

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Ben Bacarisse
Chris Angelico writes: > On Sat, Nov 20, 2021 at 3:41 PM Ben Bacarisse wrote: >> >> Chris Angelico writes: >> >> > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse >> > wrote: >> >> >> >> Chris Angelico writes: >> >> >> >> > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse >> >> > wrote: >> >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 3:41 PM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse wrote: > >> > >> Chris Angelico writes: > >> > >> > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse > >> > wrote: > >> >> > >> >> Chris Angelico writes: > >> >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Ben Bacarisse
Chris Angelico writes: > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse wrote: >> >> Chris Angelico writes: >> >> > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse wrote: >> >> >> >> Chris Angelico writes: >> >> >> >> > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: >> >> >> >> >> >>> 0.3 + 0.3 +

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse wrote: > >> > >> Chris Angelico writes: > >> > >> > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: > >> > >> >> >>> 0.3 + 0.3 + 0.3 == 0.9 > >> >> False > >> > > >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Ben Bacarisse
Chris Angelico writes: > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse wrote: >> >> Chris Angelico writes: >> >> > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: >> >> >> >>> 0.3 + 0.3 + 0.3 == 0.9 >> >> False >> > >> > That's because 0.3 is not 3/10. It's not because floats are >> > "unreliable"

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread dn via Python-list
On 20/11/2021 10.21, Chris Angelico wrote: > On Sat, Nov 20, 2021 at 7:39 AM dn via Python-list > wrote: >>> 0.3 + 0.3 + 0.3 == 0.9 False >>> >>> That's because 0.3 is not 3/10. It's not because floats are >>> "unreliable" or "inaccurate". It's because the ones you're entering >>> are n

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: > > >> >>> 0.3 + 0.3 + 0.3 == 0.9 > >> False > > > > That's because 0.3 is not 3/10. It's not because floats are > > "unreliable" or "inaccurate". It's because the on

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Ben Bacarisse
Chris Angelico writes: > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: >> >>> 0.3 + 0.3 + 0.3 == 0.9 >> False > > That's because 0.3 is not 3/10. It's not because floats are > "unreliable" or "inaccurate". It's because the ones you're entering > are not what you think they are. > > When will peop

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 7:39 AM dn via Python-list wrote: > >> >>> 0.3 + 0.3 + 0.3 == 0.9 > >> False > > > > That's because 0.3 is not 3/10. It's not because floats are > > "unreliable" or "inaccurate". It's because the ones you're entering > > are not what you think they are. > > > > When will p

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread dn via Python-list
On 20/11/2021 09.17, Chris Angelico wrote: > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: >> Le 19/11/2021 à 03:51, MRAB a écrit : >>> On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: > Working with floats i notic

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 5:08 AM ast wrote: > > Le 19/11/2021 à 03:51, MRAB a écrit : > > On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: > >> On 2021-11-18 at 23:16:32 -0300, > >> René Silva Valdés wrote: > >> > >>> Hello, I would like to report the following issue: > >>> > >>> Wor

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Mats Wichmann
On 11/18/21 19:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: Hello, I would like to report the following issue: Working with floats i noticed that: int(23.99/12) returns 1, and int(23.999/12) returns 2 This im

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread ast
Le 19/11/2021 à 12:43, ast a écrit : Le 19/11/2021 à 03:51, MRAB a écrit : On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: Hello, I would like to report the following issue: Working with floats i noticed that: int(23.

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread ast
Le 19/11/2021 à 03:51, MRAB a écrit : On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: Hello, I would like to report the following issue: Working with floats i noticed that: int(23.99/12) returns 1, and int(

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-18 Thread MRAB
On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: Hello, I would like to report the following issue: Working with floats i noticed that: int(23.99/12) returns 1, and int(23.999/12) returns 2 This

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-18 Thread 2QdxY4RzWzUUiLuE
On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: > Hello, I would like to report the following issue: > > Working with floats i noticed that: > > int(23.99/12) returns 1, and > int(23.999/12) returns 2 > > This implies that int() function is rounding ... It's

Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-18 Thread René Silva Valdés
g about it). Looking further i noticed that 0.5+0.49994 returns 1. This seems to be related to double numbers' operations in C language, where 0.49994 is the greatest floating-point value less than 0.5. Counting on this several examples can be deduced, like: round(0+0.49

round decimal values

2021-06-24 Thread jo
Hi, this code generate 4 values with gaussian distribution (mu=5, sigma=1): import numpy as np x = np.random.normal(5, 1, 4) print(x) Output: [5.87879753 3.29162433 3.83024698 4.92997148] I would like to round the output like this: [6, 3, 4, 5] What should I add to the code? Thank you j

Re: round decimal values

2021-06-24 Thread jo
gt;> >> Output: >> [5.87879753 3.29162433 3.83024698 4.92997148] >> >> I would like to round the output like this: >> >> [6, 3, 4, 5] >> >> What should I add to the code? >> >> Thank you > > Have a look at numpy.around: > <

FlaskCon is round the corner!

2020-05-06 Thread Abdur-Rahmaan Janhangeer
Greetings list, FlaskCon is coming soon. It will be a 100% remote event with paper reviews by the Pallets team. It is a collaborative event and a first attempt of it's kind. In an attempt to include as much people as we can from the community we prepared a form to gather some ideas. https://form

Re: Why emumerated list is empty on 2nd round of print?

2018-09-07 Thread Oscar Benjamin
On Fri, 7 Sep 2018 at 16:25, Schachner, Joseph wrote: >... > Now, on to the second part: the problem you showed - that you can only loop > through aList:print(i,j) once - is BECAUSE you hung onto it from one loop to > another. Once the iterator is exhausted, it's exhausted. > > Think of another

RE: Why emumerated list is empty on 2nd round of print?

2018-09-07 Thread Schachner, Joseph
should not hold the iterator from one loop to the next, you have to make another one. --- Joe S. -Original Message- From: Viet Nguyen Sent: Thursday, September 6, 2018 2:50 PM To: python-list@python.org Subject: Re: Why emumerated list is empty on 2nd round of print? On Thursday, September

Re: Why emumerated list is empty on 2nd round of print?

2018-09-06 Thread Steven D'Aprano
On Thu, 06 Sep 2018 11:50:17 -0700, Viet Nguyen via Python-list wrote: > If I do this "aList = enumerate(numList)", isn't it > stored permanently in aList now? Yes, but the question is "what is *it* that is stored? The answer is, it isn't a list, despite the name you choose. It is an enumerate i

Re: Why emumerated list is empty on 2nd round of print?

2018-09-06 Thread Viet Nguyen via Python-list
t.__next__() > (4, 1) > >>> aList.__next__() > (5, 8) > >>> aList.__next__() > Traceback (most recent call last): > File "", line 1, in > StopIteration > >>> > > > -Original Message- > From: Python-list > [mailt

Re: Why emumerated list is empty on 2nd round of print?

2018-09-06 Thread Chris Angelico
On Fri, Sep 7, 2018 at 4:50 AM, Viet Nguyen via Python-list wrote: >> Because it's not an enumerated list, it's an enumerated iterator. >> Generally, you'll just use that directly in the loop: >> >> for i, value in enumerate(numbers): >> >> There's generally no need to hang onto it from one loop t

RE: Why emumerated list is empty on 2nd round of print?

2018-09-06 Thread David Raymond
- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of Viet Nguyen via Python-list Sent: Thursday, September 06, 2018 2:50 PM To: python-list@python.org Subject: Re: Why emumerated list is empty on 2nd round of print? On Thursday, September 6, 2018 at 10

Re: Why emumerated list is empty on 2nd round of print?

2018-09-06 Thread Viet Nguyen via Python-list
On Thursday, September 6, 2018 at 10:34:19 AM UTC-7, Chris Angelico wrote: > On Fri, Sep 7, 2018 at 3:26 AM, Viet Nguyen via Python-list > wrote: > numList > > [2, 7, 22, 30, 1, 8] > > > aList = enumerate(numList) > > > for i,j in aList:print(i,j) > > > > 0 2 > > 1 7 > > 2 22 > > 3

Re: Why emumerated list is empty on 2nd round of print?

2018-09-06 Thread Chris Angelico
On Fri, Sep 7, 2018 at 3:26 AM, Viet Nguyen via Python-list wrote: numList > [2, 7, 22, 30, 1, 8] > aList = enumerate(numList) > for i,j in aList:print(i,j) > > 0 2 > 1 7 > 2 22 > 3 30 > 4 1 > 5 8 > for i,j in aList:print(i,j) > Because it's not an enumerated list, it's a

Why emumerated list is empty on 2nd round of print?

2018-09-06 Thread Viet Nguyen via Python-list
>>> numList [2, 7, 22, 30, 1, 8] >>> aList = enumerate(numList) >>> for i,j in aList:print(i,j) 0 2 1 7 2 22 3 30 4 1 5 8 >>> for i,j in aList:print(i,j) >>> -- https://mail.python.org/mailman/listinfo/python-list

Re: round

2018-06-07 Thread Steven D'Aprano
On Thu, 07 Jun 2018 13:09:18 +0200, ast wrote: > Hi > > round is supposed to provide an integer when called without any > precision argument. True, but that's really under the control of the object you feed it to. It would be possible for round() to enforce that, but it might

Re: round

2018-06-07 Thread Peter Otten
ast wrote: > Hi > > round is supposed to provide an integer when > called without any precision argument. > > here is the doc: > > >>> help(round) > > round(number[, ndigits]) -> number > > Round a number to a given precision in decimal digit

Re: round

2018-06-07 Thread Lutz Horn
M = np.array([[0, 9],[2, 7]], dtype=int) np.linalg.det(M) -18.004 round(np.linalg.det(M)) np.linalg.det(M) has type numpy.float64, not float. Try this: round(float(np.linalg.det(M))) -18 Lutz -- https://mail.python.org/mailman/listinfo/python-list

round

2018-06-07 Thread ast
Hi round is supposed to provide an integer when called without any precision argument. here is the doc: >>> help(round) round(number[, ndigits]) -> number Round a number to a given precision in decimal digits (default 0 digits). This returns an int when called with one argumen

Re: Round to 2 decimal places

2017-12-06 Thread Steve D'Aprano
pt for this to work. python3.5 -c "volume = 257.148345678; print(round(volume, 2))" (Do you need help opening a terminal window? If so, ask. We'll need to know your operating system, and if you are using Linux, which desktop environment you are using.) If your prompt is &qu

Re: Round to 2 decimal places

2017-12-06 Thread Steve D'Aprano
On Thu, 7 Dec 2017 11:58 am, nick martinez wrote: > I'm stuck. I need my program to round the end solution to 2 decimal places > but cant figure it out. Can someone help? I've been trying between printf > and round() but cant seem to get either to work. It might help if yo

Re: Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
t; h = float(h) > > > > if r > 0 and h > 0: > > > > > > > > surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + > > > > h ** 2)) > > > > volume = (1 / 3) * math.pi * r ** 2 * h > > > > >

Re: Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
h > > > ** 2)) > > > volume = (1 / 3) * math.pi * r ** 2 * h > > > > > > print() > > > print("Your Answer is:") > > > print() > > > > > > print("A cone with radius", r, "\nand heigh

Re: Round to 2 decimal places

2017-12-06 Thread MRAB
* 2 * h print() print("Your Answer is:") print() print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", round(volume,2), "\nand surface area of : ", round(surfacearea,2), ) else: print("N

Re: Round to 2 decimal places

2017-12-06 Thread ssghotra1997
> > if r > 0 and h > 0: > > > > surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** > > 2)) > > volume = (1 / 3) * math.pi * r ** 2 * h > > > > print() > > print("Your Answer is:") > > print(

Re: Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
volume = (1 / 3) * math.pi * r ** 2 * h > > print() > print("Your Answer is:") > print() > > print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : > ", round(volume,2), "\nand surface area of : "

Re: Round to 2 decimal places

2017-12-06 Thread ssghotra1997
= float(h) if r > 0 and h > 0: surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 2)) volume = (1 / 3) * math.pi * r ** 2 * h print() print("Your Answer is:") print() print("A cone with radius", r, "\nand height of", h

Re: Round to 2 decimal places

2017-12-06 Thread ssghotra1997
t(r) h = float(h) if r > 0 and h > 0: surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 2)) volume = (1 / 3) * math.pi * r ** 2 * h print() print("Your Answer is:") print() print("A cone with radius", r, "\nand height of&

Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
I'm stuck. I need my program to round the end solution to 2 decimal places but cant figure it out. Can someone help? I've been trying between printf and round() but cant seem to get either to work. Python 3.5 is what I'm using. import math print("This program will calculate

django float round tripping

2017-04-07 Thread Robin Becker
I've been having problems with django FloatFields not round tripping properly; eg field = 0.018903438896219302 gets saved and returns as 0.0189034388962193 It turns out that this is a property of the MySQLdb python interface where in converter.py we have the definition def Float2Str

Round-Trip Object Correspondence, Weakrefs And __new__

2016-08-09 Thread Lawrence D’Oliveiro
Qahirah is a Pythonic API binding for the Cairo 2D graphics library. When designing it, I tried to imagine how the graphics API would look if had been created for Python in the first place, rather than for C. One of the important decisions I made was to implemen

Re: How to program round this poplib error?

2016-03-11 Thread dieter
c...@isbd.net writes: > I have a (fairly simple) Python program that scans through a > 'catchall' E-Mail address for things that *might* be for me. It sends > anything that could be for me to my main E-Mail and discards the rest. > > However I *occasionally* get an error from it as follows:- > >

Re: How to program round this poplib error?

2016-03-10 Thread cl
Jon Ribbens wrote: > On 2016-03-10, c...@isbd.net wrote: > > # Read each message into a string and then parse with the email > > module, if > > # there's an error retrieving the message then just throw it away > > # > > try: > > popmsg = pop3.retr(i

Re: How to program round this poplib error?

2016-03-10 Thread cl
Mark Lawrence wrote: > On 10/03/2016 12:04, c...@isbd.net wrote: > > I have a (fairly simple) Python program that scans through a > > 'catchall' E-Mail address for things that *might* be for me. It sends > > anything that could be for me to my main E-Mail and discards the rest. > > > > However I

Re: How to program round this poplib error?

2016-03-10 Thread Jon Ribbens
On 2016-03-10, c...@isbd.net wrote: > # Read each message into a string and then parse with the email > module, if > # there's an error retrieving the message then just throw it away > # > try: > popmsg = pop3.retr(i+1) > except: >

Re: How to program round this poplib error?

2016-03-10 Thread Mark Lawrence
On 10/03/2016 12:04, c...@isbd.net wrote: I have a (fairly simple) Python program that scans through a 'catchall' E-Mail address for things that *might* be for me. It sends anything that could be for me to my main E-Mail and discards the rest. However I *occasionally* get an error from it as fo

How to program round this poplib error?

2016-03-10 Thread cl
I have a (fairly simple) Python program that scans through a 'catchall' E-Mail address for things that *might* be for me. It sends anything that could be for me to my main E-Mail and discards the rest. However I *occasionally* get an error from it as follows:- Traceback (most recent call las

Re: Error while calling round() from future.builtins

2014-05-12 Thread Preethi
mal' has no attribute 'from_float'" when I run the following in > > > python prompt: > > > > > >>>> from future.builtins import int, round > > > > I get an error when I try that: > > > > > >

Re: Error while calling round() from future.builtins

2014-05-10 Thread Jerry Hill
On Sat, May 10, 2014 at 7:39 AM, Preethi wrote: > future==0.9.0 It looks like that library is out of date. The current version looks to be 0.12.0, and it also looks like this bug was fixed in the 0.12.0 release. I'd upgrade your version if at all possible. -- Jerry -- https://mail.python.org

Re: Error while calling round() from future.builtins

2014-05-10 Thread Steven D'Aprano
On Sat, 10 May 2014 04:39:05 -0700, Preethi wrote: > Hi, > > I am new to python. I am getting an error "AttributeError: type object > 'Decimal' has no attribute 'from_float'" when I run the following in > python prompt: > >>>> from f

Error while calling round() from future.builtins

2014-05-10 Thread Preethi
Hi, I am new to python. I am getting an error "AttributeError: type object 'Decimal' has no attribute 'from_float'" when I run the following in python prompt: >>> from future.builtins import int, round >>> int(round(5)) Traceback (most recent

Re: How to round trip python and sqlite dates

2013-11-17 Thread Mark Lawrence
file dbapi2.py I found references to convert_date and convert_timestamp, but putting print statements in them and they didn't appear to be called. So how do I achieve the round trip that I'd like, or do I simply cut my loses and use strptime on the string that I can see returned? N

Re: How to round trip python and sqlite dates

2013-11-16 Thread Paul Simon
ate > return datetime.strptime(datetimestr, '%Y-%m-%d') > TypeError: must be str, not bytes > > However if I comment out the register_converter line this output is > printed > > 2013-11-18 > > Further digging in the sqlite3 file dbapi2.py I found references

How to round trip python and sqlite dates

2013-11-16 Thread Mark Lawrence
convert_date and convert_timestamp, but putting print statements in them and they didn't appear to be called. So how do I achieve the round trip that I'd like, or do I simply cut my loses and use strptime on the string that I can see returned? Note that I won't be checking repli

Re: round off to two decimal & return float

2013-04-01 Thread ஆமாச்சு
On Saturday 30 March 2013 03:14 PM, Peter Otten wrote: > style = xlwt.XFStyle() > style.num_format_str = "0.00" Yes. That was really helpful & what I expected. Thank you. -- http://mail.python.org/mailman/listinfo/python-list

Re: round off to two decimal & return float

2013-03-30 Thread rurpy
On 03/30/2013 10:41 AM, Dennis Lee Bieber wrote: > On Sat, 30 Mar 2013 13:22:59 +0530, ??? declaimed > the following in gmane.comp.python.general: > >> Consider the scenario, >> >> >> a = 10 >> >> "{0:.2f}".format(a) >> '10.00' >> >> This returns a string 10.00. But what is the preferred me

Re: round off to two decimal & return float

2013-03-30 Thread Grant Edwards
On 2013-03-30, ? wrote: > On Saturday 30 March 2013 02:58 PM, Roland Mueller wrote: >> >> >> >> I assume you have a numeric value a and want to have a float with 2 >> decimals. This can be achieved with the function round(): > > But I ne

Re: round off to two decimal & return float

2013-03-30 Thread Roland Mueller
retain >> 10.0 (float) as 10.00 (float)? >> >> I assume you have a numeric value a and want to have a float with 2 > decimals. This can be achieved with the function round(): > > Of course the representation of the float having a given number of decimals printed out i

Re: round off to two decimal & return float

2013-03-30 Thread Peter Otten
ஆமாச்சு wrote: > Consider the scenario, > >>> a = 10 >>> "{0:.2f}".format(a) > '10.00' > > This returns a string 10.00. But what is the preferred method to retain > 10.0 (float) as 10.00 (float)? You can use round() to convert 1.226 to 1

Re: round off to two decimal & return float

2013-03-30 Thread ஆமாச்சு
On Saturday 30 March 2013 02:58 PM, Roland Mueller wrote: > > > > I assume you have a numeric value a and want to have a float with 2 > decimals. This can be achieved with the function round(): But I need 10.00 and not 10.0 -- http://mail.python.org/mailman/listinfo/python-list

Re: round off to two decimal & return float

2013-03-30 Thread pyplexed
Hi Sri. I'm not familiar with the xlwt module, but I think you are confusing two different things here. Generally spreadsheets separate out how they handle the value in a cell (the value) and how that value is displayed (the format). This means that the you leave the cell value unchanged when

Re: round off to two decimal & return float

2013-03-30 Thread Roland Mueller
numeric value a and want to have a float with 2 decimals. This can be achieved with the function round(): >>> a = 10 >>> type(a) >>> a = round(10,2) >>> type (a) >>> a 10.0 BR, Roland > I am trying to assign the value to a cell of a s

round off to two decimal & return float

2013-03-30 Thread ஆமாச்சு
Consider the scenario, >> a = 10 >> "{0:.2f}".format(a) '10.00' This returns a string 10.00. But what is the preferred method to retain 10.0 (float) as 10.00 (float)? I am trying to assign the value to a cell of a spreadsheet, using python-xlwt. I would like to have 10.00 as the value that is ri

Re: round down to nearest number

2012-02-11 Thread Hrvoje Niksic
Terry Reedy writes: > On 2/9/2012 8:23 PM, noydb wrote: >> So how would you round UP always? Say the number is 3219, so you want >>>> (//100+1)*100 > 3400 Note that that doesn't work for numbers that are already round: >>> (3300//100+1)*100 3400

Re: round down to nearest number

2012-02-10 Thread Olive
On Thu, 9 Feb 2012 17:43:58 -0800 Chris Rebert wrote: > On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: > > hmmm, okay. > > > > So how would you round UP always?  Say the number is 3219, so you > > want 3300 returned. > > http://stackoverflow.com/questions/17

  1   2   3   4   >