Re: Lucky numbers in Python

2015-04-30 Thread Dave Angel
On 04/30/2015 02:55 PM, Cecil Westerhof wrote: Because I want the code to work with Python 3 also, the code is now: def lucky_numbers(n): """ Lucky numbers from 1 up-to n http://en.wikipedia.org/wiki/Lucky_number """ if n < 3: return

Re: Lucky numbers in Python

2015-04-30 Thread Cecil Westerhof
Because I want the code to work with Python 3 also, the code is now: def lucky_numbers(n): """ Lucky numbers from 1 up-to n http://en.wikipedia.org/wiki/Lucky_number """ if n < 3: return [1] sieve = list(range(1, n + 1, 2)) si

Re: Lucky numbers in Python

2015-04-30 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 04:55 CEST schreef Ian Kelly: > On Wed, Apr 29, 2015 at 6:01 PM, Cecil Westerhof wrote: >> Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: >>> In that case you can definitely omit the middle term of the slice, >>> which will be both more concise and clearer in intent

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 6:11 PM, Steven D'Aprano wrote: > On Thu, 30 Apr 2015 05:57 am, Ian Kelly wrote: > >> On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof >> wrote: >>> I was wondering if there is a way to do this: >>> for del_index in range((sieve_len // skip_count) * skip_count

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 6:01 PM, Cecil Westerhof wrote: > Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: >> In that case you can definitely omit the middle term of the slice, >> which will be both more concise and clearer in intent, though >> probably not significantly faster. > > It is cer

Re: Lucky numbers in Python

2015-04-29 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: > On Wed, Apr 29, 2015 at 3:45 PM, Cecil Westerhof wrote: >> Op Wednesday 29 Apr 2015 21:57 CEST schreef Ian Kelly: >>> And although it's not clear to me what this is supposed to be >>> doing, you probably no longer need the middle term if the

Re: Lucky numbers in Python

2015-04-29 Thread Steven D'Aprano
On Thu, 30 Apr 2015 05:57 am, Ian Kelly wrote: > On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof > wrote: >> I was wondering if there is a way to do this: >> for del_index in range((sieve_len // skip_count) * skip_count >> - 1, >> skip_c

Re: Lucky numbers in Python

2015-04-29 Thread Chris Kaynor
On Wed, Apr 29, 2015 at 2:45 PM, Cecil Westerhof wrote: > >> I was wondering if there is a way to do this: > >> for del_index in range((sieve_len // skip_count) * skip_count - 1, > >> skip_count - 2, -skip_count): > >> del sieve[del_index] > >> in a more efficient way. > > > > You can delete usin

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 3:45 PM, Cecil Westerhof wrote: > Op Wednesday 29 Apr 2015 21:57 CEST schreef Ian Kelly: >> And although it's not clear to me what this is supposed to be doing, >> you probably no longer need the middle term if the intention is to >> continue deleting all the way to the end

Re: Lucky numbers in Python

2015-04-29 Thread Cecil Westerhof
Op Wednesday 29 Apr 2015 21:57 CEST schreef Ian Kelly: > On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof wrote: >> I was wondering if there is a way to do this: >> for del_index in range((sieve_len // skip_count) * skip_count - 1, >> skip_count - 2, -skip_count): >> del sieve[del_index] >> in a

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof wrote: > I was wondering if there is a way to do this: > for del_index in range((sieve_len // skip_count) * skip_count - 1, > skip_count - 2, -skip_count): > del sieve[del_index] > in a

Lucky numbers in Python

2015-04-29 Thread Cecil Westerhof
I wrote a function lucky_numbers: def lucky_numbers(n): if n < 3: return [1] sieve = range(1, n + 1, 2) sieve_index = 1 while True: skip_count = sieve[sieve_index] sieve_len = len(sieve) if sieve_len < skip_count

Re: Question on using FP numbers in python 2

2014-02-15 Thread Gene Heskett
On Saturday 15 February 2014 12:13:42 Steven D'Aprano did opine: > On Sat, 15 Feb 2014 00:07:49 -0500, Gene Heskett wrote: > >> Can you extract the float calculations and show us, together with > >> some sample data, expected result, and actual result? > > > > Not extract, but let you get & look

Re: Question on using FP numbers in python 2

2014-02-15 Thread Steven D'Aprano
On Sat, 15 Feb 2014 00:07:49 -0500, Gene Heskett wrote: >> Can you extract the float calculations and show us, together with some >> sample data, expected result, and actual result? > > Not extract, but let you get & look at the code, its the top entry on > this page: > >

Re: Question on using FP numbers in python 2

2014-02-14 Thread Chris Angelico
On Sat, Feb 15, 2014 at 4:50 PM, Gene Heskett wrote: >> I'm afraid I can't really help more, as I don't speak CNC. > > Actually, the output is RS-274-D, originally from NIST. But it has > developed some pretty distinct "accents" in the 20 some years its been in > the wild. The NIST version was,

Re: Question on using FP numbers in python 2

2014-02-14 Thread Gene Heskett
On Saturday 15 February 2014 00:43:53 Chris Angelico did opine: > On Sat, Feb 15, 2014 at 4:07 PM, Gene Heskett wrote: > > Not extract, but let you get & look at the code, its the top entry on > > this page: > > > > > Code_Generators

Re: Question on using FP numbers in python 2

2014-02-14 Thread Chris Angelico
On Sat, Feb 15, 2014 at 4:07 PM, Gene Heskett wrote: > Not extract, but let you get & look at the code, its the top entry on this > page: > > Code_Generators#Counterbore_Software> Interesting. At the top of the file, it says GPL3 or l

Re: Question on using FP numbers in python 2

2014-02-14 Thread Gene Heskett
On Friday 14 February 2014 23:47:26 Steven D'Aprano did opine: > On Fri, 14 Feb 2014 22:25:59 -0500, Gene Heskett wrote: > > Greetings; > > > > Is there something I can search for and fix in some python code that > > is giving me bogus answers that get good only when there is a valid > > digit to

Re: Question on using FP numbers in python 2

2014-02-14 Thread Gene Heskett
On Friday 14 February 2014 23:37:53 Chris Angelico did opine: > On Sat, Feb 15, 2014 at 2:25 PM, Gene Heskett wrote: > > Is there something I can search for and fix in some python code that > > is giving me bogus answers that get good only when there is a valid > > digit to the left of the decima

Re: Question on using FP numbers in python 2

2014-02-14 Thread Grant Edwards
On 2014-02-15, Gene Heskett wrote: > Is there something I can search for and fix in some python code that > is giving me bogus answers that get good only when there is a valid > digit to the left of the decimal point? Yes. Search for incorrectly written code and fix it. I'd start part way down

Re: Question on using FP numbers in python 2

2014-02-14 Thread Steven D'Aprano
On Fri, 14 Feb 2014 22:25:59 -0500, Gene Heskett wrote: > Greetings; > > Is there something I can search for and fix in some python code that is > giving me bogus answers that get good only when there is a valid digit > to the left of the decimal point? Er, yes? Anything which involves floating

Re: Question on using FP numbers in python 2

2014-02-14 Thread Chris Angelico
On Sat, Feb 15, 2014 at 2:25 PM, Gene Heskett wrote: > Is there something I can search for and fix in some python code that is > giving me bogus answers that get good only when there is a valid digit to > the left of the decimal point? > Interesting. I'd look for anything that mixes very large an

Question on using FP numbers in python 2

2014-02-14 Thread Gene Heskett
Greetings; Is there something I can search for and fix in some python code that is giving me bogus answers that get good only when there is a valid digit to the left of the decimal point? Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Ple

Re: How to print zero-padded floating point numbers in python 2.6.1

2009-11-04 Thread Chris Rebert
On Wed, Nov 4, 2009 at 12:04 AM, Lorenzo Di Gregorio wrote: > Hello, > > I thought that I could zero-pad a floating point number in 'print' by > inserting a zero after '%', but this does not work. > > I get: > > print '%2.2F' % 3.5 > 3.50 > print '%02.2F' % 3.5 > 3.50 > > How can I get print (in a

Re: How to print zero-padded floating point numbers in python 2.6.1

2009-11-04 Thread Lutz Horn
Lorenzo Di Gregorio schrieb: > print '%2.2F' % 3.5 > 3.50 > print '%02.2F' % 3.5 > 3.50 > > How can I get print (in a simple way) to print 03.50? print '%05.2F' % 3.5 Lutz -- http://mail.python.org/mailman/listinfo/python-list

How to print zero-padded floating point numbers in python 2.6.1

2009-11-04 Thread Lorenzo Di Gregorio
Hello, I thought that I could zero-pad a floating point number in 'print' by inserting a zero after '%', but this does not work. I get: print '%2.2F' % 3.5 3.50 print '%02.2F' % 3.5 3.50 How can I get print (in a simple way) to print 03.50? Best Regards, Lorenzo -- http://mail.python.org/mail

Localizing numbers in python

2007-08-16 Thread Heba Farouk
Hello i would like to localize numbers in python according to the current selected language of the web page (English, french, arabic, ...), is there any options in python?? thanks in advance Yours Heba - Take the Internet to Go: Yahoo!Go puts the

Re: Numbers in python

2006-03-10 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: >> However, I can't seem to get the program to treat the numbers as >> numbers. If I put them in the dictionary as 'THE' = int(0.965) the >> program returns 1.0 > >It certainoly does _not_ return 1.0 - it returns 1. And tha

Re: Numbers in python

2006-03-10 Thread Steve Holden
[EMAIL PROTECTED] wrote: > 'It certainoly does _not_ return 1.0 - it returns 1. And that is all it > can > return for being an integer that has by definition no fractional part. > ' > > For goodness sake, it was a typo, I'm so sorry! > Guess that's what you get for calling yourself "brainy_muppet

Re: Numbers in python

2006-03-10 Thread neildunn
If your still worried by using floats for your values you may wish to look into the decimal module: http://docs.python.org/lib/module-decimal.html Example: >>> from decimal import Decimal >>> Decimal(2) + Decimal('1.47') Decimal("3.47") Regards, Neil -- http://mail.python.org/mailman/listinf

Re: Numbers in python

2006-03-10 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with: > if I put 'THE' = float(0.965) it returns 0.9655549 or something > similar. That's for the same reasons as you can't write 1/3rd in decimal notation. Computers can't write 1/10th in binary notation. Sybren -- The problem with the world is stupidity. No

Re: Numbers in python

2006-03-10 Thread brainy_muppet
'It certainoly does _not_ return 1.0 - it returns 1. And that is all it can return for being an integer that has by definition no fractional part. ' For goodness sake, it was a typo, I'm so sorry! -- http://mail.python.org/mailman/listinfo/python-list

Re: Numbers in python

2006-03-10 Thread Diez B. Roggisch
> It certainoly does _not_ return 1.0 - it returns 1. And that is all it can > return for being an integer that has by definition no fractional part. Duncan was right of course. It returns 0. Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: Numbers in python

2006-03-10 Thread brainy_muppet
'It certainoly does _not_ return 1.0 - it returns 1. And that is all it can return for being an integer that has by definition no fractional part. ' For goodness sake, it was a typo, I'm so sorry! -- http://mail.python.org/mailman/listinfo/python-list

Re: Numbers in python

2006-03-10 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Basically, I have a code with is almost finished but I've having > difficultly with the last stage of the process. I have a program that > gets assigns different words with a different value via looking them up > in a dictionary: > > eg if THE is in the writing, it assig

Re: Numbers in python

2006-03-10 Thread Duncan Booth
wrote: > If I put them in the dictionary as 'THE' = int(0.965) the > program returns 1.0 and if I put 'THE' = float(0.965) it returns > 0.9655549 or something similar. Neither of these are right! Your system seems to be really screwed. int(0.965) should be 0, and float(0.965) should be 0.96

Re: Numbers in python

2006-03-10 Thread Diez B. Roggisch
> However, I can't seem to get the program to treat the numbers as > numbers. If I put them in the dictionary as 'THE' = int(0.965) the > program returns 1.0 It certainoly does _not_ return 1.0 - it returns 1. And that is all it can return for being an integer that has by definition no fractional

Numbers in python

2006-03-10 Thread brainy_muppet
Basically, I have a code with is almost finished but I've having difficultly with the last stage of the process. I have a program that gets assigns different words with a different value via looking them up in a dictionary: eg if THE is in the writing, it assigns 0.965 and once the whole passage