Re: [Tutor] A couple newbie questions about Python

2014-06-13 Thread Deb Wyatt
 -Original Message-
 From: breamore...@yahoo.co.uk
 Sent: Thu, 12 Jun 2014 09:18:16 +0100
 To: tutor@python.org
 Subject: Re: [Tutor] A couple newbie questions about Python
 
 Please don't top post, it makes following a long thread extremely
 difficult, thanks.
 
sorry.  The other python list wants you to, so I just assumed...

Deb in WA, USA

She says as she almost top posts again :P...


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks  orcas on your 
desktop!
Check it out at http://www.inbox.com/marineaquarium


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-12 Thread Deb Wyatt

Thanks very much Alan.  As for the my concern about inaccuracy in float math, I 
suppose I am concerned because I was not aware of the issue before, and I 
wonder how you deal with such things when you need accuracy for financial 
things.

Deb in WA, USA


 -Original Message-
 From: alan.ga...@btinternet.com
 Sent: Wed, 11 Jun 2014 23:48:37 +0100
 To: tutor@python.org
 Subject: Re: [Tutor] A couple newbie questions about Python
 
 On 11/06/14 21:46, Deb Wyatt wrote:
 Hi.  Everywhere I have read, the 'standard practice' for indentation is
 4 spaces,
 
 That's a style recommendation. Python doesn't care.
 But your readers will. 2 spaces is the absolute minimum,
 8 spaces is about the absolute maximum. Outside that it
 gets hard to read the code.
 
 3, 4 or 5 spaces is pretty good and you are unlikely
 to get complaints except from style pedants or if you
 are submitting code for the standard library where they
 like to stick with the official guidance.
 
 
 I just recently became aware of the inaccuracy of calculations using
 floats
   and I am concerned about that.
 
 The inaccuracies are an inevitable result of the way your computer
 processes floating point numbers.
 
 In what way are you concerned? Its not a Python issue - the exact same
 issues occur in any computer - or even your pocket calculator.
 If it concerns you in Excel or in Visual Basic/Java/C++ etc too then the
 good news is that Python has alternative renderings that can often
 reduce/eliminate them - but at the cost of speed and complexity.
 
 
 HTH
 --
 Alan G
 Author of the Learn to Program web site
 http://www.alan-g.me.uk/
 http://www.flickr.com/photos/alangauldphotos
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor


Protect your computer files with professional cloud backup.
Get PCRx Backup and upload unlimited files automatically. 
Learn more at http://backup.pcrx.com/mail


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-12 Thread ALAN GAULD
I wonder how you deal with such things when you need accuracy for financial 
things.
Financial applications traditionally work in the lowest unit of currency and 
use integers.
For display purposes they convert the pennies into dollars/cents or 
pounds/pence or whatever.
 
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-12 Thread Mark Lawrence
Please don't top post, it makes following a long thread extremely 
difficult, thanks.


On 12/06/2014 03:47, Deb Wyatt wrote:


Thanks very much Alan.  As for the my concern about inaccuracy in float math, I 
suppose I am concerned because I was not aware of the issue before, and I 
wonder how you deal with such things when you need accuracy for financial 
things.

Deb in WA, USA




Besides Alan's previous statement about using integers you can also use 
things like Python's decimal module see 
https://docs.python.org/3/library/decimal.html#module-decimal


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-12 Thread eryksun
On Thu, Jun 12, 2014 at 1:27 AM, Alex Kleider aklei...@sonic.net wrote:
 On 2014-06-11 20:08, Dave Angel wrote:

 I learned programming in 1967 with Fortran,  and McCracken spent a
 chapter warning about that same thing. Probably everything he
 warned about still applies to Python and modern computers.

 A google search for McCracken did not yield anyone that seems to fit the
 person you reference. Can you clarify, please?

1961 A Guide to Fortran Programming
openlibrary.org/works/OL4628575W

1964 Numerical Methods and Fortran Programming
openlibrary.org/books/OL5914708M

1965 A Guide to Fortran IV Programming
openlibrary.org/books/OL5953402M

1967 Fortran with Engineering Applications
openlibrary.org/books/OL5539818M

snippets:
books.google.com/books?id=qQY_IAAJdq=editions:STANFORD36105002062847

1974 A Simplified Guide to Fortran Programming
openlibrary.org/works/OL4628579W

1972 Numerical Methods with Fortran IV Case Studies
openlibrary.org/books/OL4559608M

1984 Computing for Engineers and Scientists with Fortran 77
openlibrary.org/books/OL3180840M
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-12 Thread Alan Gauld

On 12/06/14 09:18, Mark Lawrence wrote:

Besides Alan's previous statement about using integers you can also use
things like Python's decimal module see
https://docs.python.org/3/library/decimal.html#module-decimal


Although Decimal doesn't solve the issue of rounding errors for 
financial calculations (neither do pennies) nor the issues of

repeating results like 1/7 It just moves them into the
more familiar territory of decimal numbers rather than binary.
So at least what you write is represented accurately.

As Steven said in his reply, floating point on computers is hard.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-11 Thread Alan Gauld

On 11/06/14 21:46, Deb Wyatt wrote:

Hi.  Everywhere I have read, the 'standard practice' for indentation is 4 
spaces,


That's a style recommendation. Python doesn't care.
But your readers will. 2 spaces is the absolute minimum,
8 spaces is about the absolute maximum. Outside that it
gets hard to read the code.

3, 4 or 5 spaces is pretty good and you are unlikely
to get complaints except from style pedants or if you
are submitting code for the standard library where they
like to stick with the official guidance.



I just recently became aware of the inaccuracy of calculations using floats

 and I am concerned about that.

The inaccuracies are an inevitable result of the way your computer 
processes floating point numbers.


In what way are you concerned? Its not a Python issue - the exact same 
issues occur in any computer - or even your pocket calculator.
If it concerns you in Excel or in Visual Basic/Java/C++ etc too then the 
good news is that Python has alternative renderings that can often 
reduce/eliminate them - but at the cost of speed and complexity.



HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-11 Thread Dave Angel
Deb Wyatt codemon...@inbox.com Wrote in message:
 Hi.  Everywhere I have read, the 'standard practice' for indentation is 4 
 spaces, but I am running into 2 space indentation in a lot of tutorials and 
 such.  Should I keep with the 4 spaces, or does it even matter, as long as it 
 is consistent?
 

4 spaces is an excellent choice in my opinion,  and many other
 people's.  We just tell our editor to turn the tab key into 4
 column alignment and pretty much forget about it.
 

The python interpreter doesn't care. But other people's opinions
 will matter as soon as you share your code, or work on a multi
 person project. 

Note that when you're looking at other people's code,  you may be
 seeing it differently than they,  chief reason being html (thank
 you for remembering to post here in text). The other reason you
 may think they're using 2 is proportional spacing. It should be
 off for code.

 I just recently became aware of the inaccuracy of calculations using floats 
 and I am concerned about that.  
 


I learned programming in 1967 with Fortran,  and McCracken spent a
 chapter warning about that same thing. Probably everything he
 warned about still applies to Python and modern computers.  It is
 impossible to do serious computing for long without running into
 these issues.  But Python has as many ways of avoiding them as
 any mainstream language.  You can use decimal to avoid some types
 of problems,  and fractions to avoid others.  And common sense
 for others.  You will need to understand your tools.
 

BTW,  calculators and spreadsheets frequently use decimal rather
 than binary,  and I wrote a decimal floating package for a
 computer in the mid 70's.  It didn't even offer binary.
 



-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-11 Thread Steven D'Aprano
Hi Deb,

My responses below, interleaved with your questions.


On Wed, Jun 11, 2014 at 12:46:11PM -0800, Deb Wyatt wrote:

 Hi.  Everywhere I have read, the 'standard practice' for indentation 
 is 4 spaces, but I am running into 2 space indentation in a lot of 
 tutorials and such.  Should I keep with the 4 spaces, or does it even 
 matter, as long as it is consistent?

Four spaces is common, and recommended by PEP 8, which describes the 
coding styles for the Python standard library:

https://www.python.org/dev/peps/pep-0008

But it's not compulsory (except for contributions to the standard 
library). There are good reasons for sticking to four spaces, but eight 
spaces or a single tab are also common. In my opinion, two spaces is too 
little, and one space is right out.

But as far as the Python interpreter is concerned, it doesn't care, so 
long as you're consistent. (However, other people reading your code may 
care.)


 I just recently became aware of the inaccuracy of calculations using 
 floats and I am concerned about that.

Floating point mathematics is tricky. What you're seeing is not a bug in 
Python, but a general problem with floating point calculations in 
general. Regardless of whether you use Python, or C, or Java, or some 
other programming language, you have to face the same issues that 
calculations with floats are not always accurate compared to what you 
expect from pure mathematics.

(Think about your calculator: how often do you get a number like 
3.001 instead of 3, or 0.499 instead of 0.5?)

You can read up on some of the issues here:

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

although it's quite technical. Some less technical discussions can be 
found here:

http://randomascii.wordpress.com/2012/04/05/floating-point-complexities/
http://support.microsoft.com/kb/42980

but however you look at it, it's complicated, and inherent to the 
problem, not the fault of Python.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-11 Thread Alex Kleider

On 2014-06-11 20:08, Dave Angel wrote:



I learned programming in 1967 with Fortran,  and McCracken spent a
 chapter warning about that same thing. Probably everything he
 warned about still applies to Python and modern computers.


A google search for McCracken did not yield anyone that seems to fit 
the person you reference.

Can you clarify, please?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A couple newbie questions about Python

2014-06-11 Thread Lukáš Němec

Hi, responses below...

Dne 11. 6. 2014 22:46, Deb Wyatt napsal(a):

Hi.  Everywhere I have read, the 'standard practice' for indentation is 4 
spaces, but I am running into 2 space indentation in a lot of tutorials and 
such.  Should I keep with the 4 spaces, or does it even matter, as long as it 
is consistent?
I recommend to use ammount of spaces that is consistent with already 
existing project.
If it is a new project, use whatever you like - 4 spaces is recommended 
(looks good :)


I just recently became aware of the inaccuracy of calculations using floats and 
I am concerned about that.
If there are numerical operations where precision is necessary 
(accounting or banking) use decimal type


from  decimal import Decimal

a = Decimal('0.1')
b = Decimal('0.9')

print a + b

Note these numbers are passed to Decimal as a string, that is for a 
reason - if you pass float to Decimal, it will already loose precision 
and the whole thing doesn't make sense - and aslo will throw an exception.


I am using Python 3, just fyi.

Thanks for any enlightenment on these questions.

Deb in WA, USA


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks  orcas on your 
desktop!
Check it out at http://www.inbox.com/marineaquarium


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Lukas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor