Re: [Tutor] what is 'doubleword alignment'?

2011-07-18 Thread Kushal Kumaran
On Sun, Jul 17, 2011 at 9:15 PM, Walter Prins wpr...@gmail.com wrote:


 On 17 July 2011 15:26, Lisi lisi.re...@gmail.com wrote:

 Sorry to be slow.  Blame virtually no sleep last night ;-(  But even were
 the
 power of two bit correct (and I see subsequently that it is not), how is
 18 a
 power of two?


 The 18 bytes is a bit of an irrelevance.  The point is that if the start of
 the buffer falls on a dword (double word) alligned memory location then in
 theory the access should be faster.  The term is a little bit ambiguous
 because strictly speaking different processors have different word sizes.
 Even so, usually when people speak of double-word alignment, it's often the
 case that the term word in such a context has its original meaning, e.g. 16
 bits.  A dword is then 32bits or 4 bytes.   A doubleword aligned memory
 address is, using these assumptions, therefore an address that is divisible
 by 4.  Obviously if the word size is 32bits, then a double word would be
 64bits and a doubleword aligned address would need to be divisible by 8.  As
 an aside, this type of optimization is often taken care of by compilers
 under the hood, and in any case it's generally not something that you'll
 really be considering as a Python programmer.  (If however you were working
 on one of the Python runtimes or implementations, then you might well be
 sometimes considering this type of thing, depending on exactly how
 performance critical what you are working might be and what the runtime was
 being implemented in.)


It's not just about performance.  Some hardware simply cannot access
data that is not correctly aligned.  C programs that indiscriminately
cast among pointers to types of different sizes are a pain to port off
lenient architectures like x86.  If you're writing C code that deals
with pointers, you *always* need to keep alignment in mind.

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


[Tutor] Good Book

2011-07-18 Thread Ryan
Dear All Pythonist,

I'm strarting learn python programming and I have been found many resources
on it but I have a problem. I don't know, what is the best complete book for
new learner like me.

I need your recommendation, thanks before . . .

-- 
It is no more than the conspiracy of 0 and 1
[decrypthor]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Good Book

2011-07-18 Thread Peter Lavelle

There's a free ebook aimed at beginners here:http://inventwithpython.com/

Regards

Peter Lavelle


On 18/07/11 09:26, Ryan wrote:

Dear All Pythonist,

I'm strarting learn python programming and I have been found many 
resources on it but I have a problem. I don't know, what is the best 
complete book for new learner like me.


I need your recommendation, thanks before . . .

--
It is no more than the conspiracy of 0 and 1
[decrypthor]


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



--
LinkedIn Profile: http://linkedin.com/in/pmjlavelle
Twitter: http://twitter.com/pmjlavelle

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


Re: [Tutor] Good Book

2011-07-18 Thread Neo Exodus
Ok, thank you All . . .

On Mon, Jul 18, 2011 at 3:36 PM, Peter Lavelle li...@solderintheveins.co.uk
 wrote:

 **
 There's a free ebook aimed at beginners here:http://inventwithpython.com/

 Regards

 Peter Lavelle



 On 18/07/11 09:26, Ryan wrote:

 Dear All Pythonist,

  I'm strarting learn python programming and I have been found many
 resources on it but I have a problem. I don't know, what is the best
 complete book for new learner like me.

  I need your recommendation, thanks before . . .

 --
 It is no more than the conspiracy of 0 and 1
 [decrypthor]


 ___
 Tutor maillist  -  Tutor@python.org

 To unsubscribe or change subscription 
 options:http://mail.python.org/mailman/listinfo/tutor



 --
 LinkedIn Profile: http://linkedin.com/in/pmjlavelle
 Twitter: http://twitter.com/pmjlavelle




-- 
It is no more than the conspiracy of 0 and 1
[decrypthor]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Good Book

2011-07-18 Thread Alan Gauld

Ryan wrote:


I'm strarting learn python programming and I have been found many resources
on it but I have a problem. I don't know, what is the best complete book for
new learner like me.


There are lots of books, both paper and electronic.
It depends on eactly what yopu want.

Can you already program in another language? If so,
the standard Python tutorial may be sufficient? If
not, one of the non-programmers tutorials
(like mine :-) will be better.

Personally I wouldn't recommed buyoing a paper book
until after you have learned the basics. Then you can
decide if you want a general reference (Python in a
Nutshell for example) or a specialist text like
Python Network Programming, say.

The Python.org site has many tutorials, in all
manner of styles, it just depends what kind of
tutorial you like.

Alan G

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


Re: [Tutor] Good Book

2011-07-18 Thread sefa yıldız
i think, this http://openbookproject.net/thinkCSpy/index.html# is good
book for you. (this http://greenteapress.com/thinkpython/thinkCSpy.pdf is
pdf version )
and also a few sources:
http://www.freenetpages.co.uk/hp/alan.gauld/
http://diveintopython.org/toc/index.html
http://www.mindview.net/Books/TIPyhttp://www.mindview.net/Books/TIPythonthonhttp://www.mindview.net/Books/TIPython
http://directory.google.com/Top/Computers/Programming/Languages/Python/FAQs,_Help,_and_Tutorials/

2011/7/18 Ryan decrypt...@gmail.com

 Dear All Pythonist,

 I'm strarting learn python programming and I have been found many resources
 on it but I have a problem. I don't know, what is the best complete book for
 new learner like me.

 I need your recommendation, thanks before . . .

 --
 It is no more than the conspiracy of 0 and 1
 [decrypthor]


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


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


Re: [Tutor] Good Book

2011-07-18 Thread Lisi
On Monday 18 July 2011 09:26:51 Ryan wrote:
 Dear All Pythonist,

 I'm strarting learn python programming and I have been found many resources
 on it but I have a problem. I don't know, what is the best complete book
 for new learner like me.

 I need your recommendation, thanks before . . .

I am using Learn Python The Hard Way by Zed A Shaw;

http://learnpythonthehardway.org/

It is basic - assumes no knowledge of programming at all and is easy to 
follow.  But as a beginning beginner myself, I find that I do most of my 
actual learning from the marvellous people on this list, with help also from 
my local Linux User Group.  The book provides the exercises and structure.

But, as has been said, your choice will depend on your own style.

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


Re: [Tutor] Good Book

2011-07-18 Thread Surya P.K. Kasturi
Actually you have a lot of books that have been quoted in www.python.org.
One of them is ThinkPython book at www.thinkpython.org. Its really good.
You'll also find exercises at the end of units.


On Mon, Jul 18, 2011 at 1:56 PM, Ryan decrypt...@gmail.com wrote:

 Dear All Pythonist,

 I'm strarting learn python programming and I have been found many resources
 on it but I have a problem. I don't know, what is the best complete book for
 new learner like me.

 I need your recommendation, thanks before . . .

 --
 It is no more than the conspiracy of 0 and 1
 [decrypthor]


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


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


[Tutor] getting error while solving a series that estimates the value of pi

2011-07-18 Thread surya k
Hi,

The problem is to estimate the value of pi using the following series.
 *1 / pi  = (( 2 * sqrt(2) )/ 9801 )  * SIGMA of k[ (4k)! (1103 + 26390*k) /
(k!^ 4 ) * 396^(4k)  ]*
*where k is [0, infinity)*
* Problem is located at : ThinkPython Book, www.thinkpython.org
   *Pg 89, Exercise 7.5, Think Python Book. *
*
*
the series should be considered till the last term of the sigma must be 
1e-15
I have written the below code :

*# program estimates the value of pi*
*# Ramanujan's series... *
*import math*
*
*
*def fact(n) : # def of factorial function.*
*if n  0 :*
*   return n * fact(n-1)*
*if n == 0 :*
*   return 1*
*
*
*k = 0*
*tot = 0*
*temp1 = 0*
*while k = 0 and temp1 == 0 :*
*
*
*  a = ( 2 * math.sqrt(2) ) / 9801 # first term before sigma *
*  nu = fact (4*k) * (1103 + (26390*k) )  # numerator of series*
*  de = pow( fact(k), 4 ) * pow ( 396, 4*k )  # denominator of series*
*  *
*  if de / nu  1e-15 : *
*temp = nu / de*
*tot = tot + temp*
*temp1 = 0 *
*k = k + 1 *
*  elif de / nu  == 1e-15 :*
* series = a * tot  *
* k = k + 1*
* temp1 = 0*
*  elif de / nu  1e-15 :*
* print series*
* temp1 = 1*


I am getting the following error : which is completely surprising!

*Traceback (most recent call last):*
*  File pi.py, line 30, in module*
*print series*
*NameError: name 'series' is not defined*

*
*
Thus I have removed name 'series' and replaced with  *a*tot, *
now I am getting this error

*Traceback (most recent call last):*
*  File pi.py, line 30, in module*
*print 1 / (a * tot)*
*ZeroDivisionError: float divisio*n



Thus I changed the first highlighted lines to

 *nu = float (fact (4*k) * (1103 + (26390*k) ) )*
*  de = float (pow( fact(k), 4 ) * pow ( 396, 4*k )) *


now I am getting

* Traceback (most recent call last):*
*  File pi.py, line 18, in module*
*de = float (pow( fact(k), 4 ) * pow ( 396, 4*k ) )*
*OverflowError: long int too large to convert to float*

*help me out of this problem, how could I fix this*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] getting error while solving a series that estimates the value of pi

2011-07-18 Thread Andre Engels
On Mon, Jul 18, 2011 at 6:10 PM, surya k sur...@live.com wrote:

 Hi,

 The problem is to estimate the value of pi using the following series.
  *1 / pi  = (( 2 * sqrt(2) )/ 9801 )  * SIGMA of k[ (4k)! (1103 + 26390*k)
 / (k!^ 4 ) * 396^(4k)  ]*
 *where k is [0, infinity)*
 * Problem is located at : ThinkPython Book, www.thinkpython.org
*Pg 89, Exercise 7.5, Think Python Book. *
 *
 *
 the series should be considered till the last term of the sigma must be 
 1e-15
 I have written the below code :

 *# program estimates the value of pi*
 *# Ramanujan's series... *
 *import math*
 *
 *
 *def fact(n) : # def of factorial function.*
 *if n  0 :*
 *   return n * fact(n-1)*
 *if n == 0 :*
 *   return 1*
 *
 *
 *k = 0*
 *tot = 0*
 *temp1 = 0*
 *while k = 0 and temp1 == 0 :*
 *
 *
 *  a = ( 2 * math.sqrt(2) ) / 9801 # first term before sigma *
 *  nu = fact (4*k) * (1103 + (26390*k) )  # numerator of series*
 *  de = pow( fact(k), 4 ) * pow ( 396, 4*k )  # denominator of series*
 *  *
 *  if de / nu  1e-15 : *
 *temp = nu / de*
 *tot = tot + temp*
 *temp1 = 0 *
 *k = k + 1 *
 *  elif de / nu  == 1e-15 :*
 * series = a * tot  *
 * k = k + 1*
 * temp1 = 0*
 *  elif de / nu  1e-15 :*
 * print series*
 * temp1 = 1*


 I am getting the following error : which is completely surprising!

 *Traceback (most recent call last):*
 *  File pi.py, line 30, in module*
 *print series*
 *NameError: name 'series' is not defined*

 *
 *
 Thus I have removed name 'series' and replaced with  *a*tot, *
 now I am getting this error

 *Traceback (most recent call last):*
 *  File pi.py, line 30, in module*
 *print 1 / (a * tot)*
 *ZeroDivisionError: float divisio*n



 Thus I changed the first highlighted lines to

  *nu = float (fact (4*k) * (1103 + (26390*k) ) )*
 *  de = float (pow( fact(k), 4 ) * pow ( 396, 4*k )) *


 now I am getting

 * Traceback (most recent call last):*
 *  File pi.py, line 18, in module*
 *de = float (pow( fact(k), 4 ) * pow ( 396, 4*k ) )*
 *OverflowError: long int too large to convert to float*

 *help me out of this problem, how could I fix this*


You have the definitions of numerator and denominator switched.

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] getting error while solving a series that estimates the value of pi

2011-07-18 Thread Alan Gauld

surya k wrote:


*k = 0*
*tot = 0*
*temp1 = 0*
*while k = 0 and temp1 == 0 :*
*  a = ( 2 * math.sqrt(2) ) / 9801 # first term before sigma *
*  nu = fact (4*k) * (1103 + (26390*k) )  # numerator of series*
*  de = pow( fact(k), 4 ) * pow ( 396, 4*k )  # denominator of series*
*  *
*  if de / nu  1e-15 : *
*temp = nu / de*
*tot = tot + temp*
*temp1 = 0 *
*k = k + 1 *
*  elif de / nu  == 1e-15 :*
* series = a * tot  *


Note that this is the only place you ever define series


* k = k + 1*
* temp1 = 0*
*  elif de / nu  1e-15 :*
* print series*


So if you ever get here without de/nu having previously been *exactly* 
1e-15 (which is pretty likely IMHO) you will get a name error.



* temp1 = 1*


I am getting the following error : which is completely surprising!

*Traceback (most recent call last):*
*  File pi.py, line 30, in module*
*print series*
*NameError: name 'series' is not defined*


Doesn't surprise me at all...


Thus I have removed name 'series' and replaced with  *a*tot, *
now I am getting this error


This is known as poke 'n hope debugging.
Better to work out why you got the previous error
message and fix it there. print statements are
your friend

HTH,

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


Re: [Tutor] getting error while solving a series that estimates the value of pi

2011-07-18 Thread James Reynolds
On Mon, Jul 18, 2011 at 12:10 PM, surya k sur...@live.com wrote:

 Hi,

 The problem is to estimate the value of pi using the following series.
  *1 / pi  = (( 2 * sqrt(2) )/ 9801 )  * SIGMA of k[ (4k)! (1103 + 26390*k)
 / (k!^ 4 ) * 396^(4k)  ]*
 *where k is [0, infinity)*
 * Problem is located at : ThinkPython Book, www.thinkpython.org
*Pg 89, Exercise 7.5, Think Python Book. *
 *
 *
 the series should be considered till the last term of the sigma must be 
 1e-15
 I have written the below code :

 *# program estimates the value of pi*
 *# Ramanujan's series... *
 *import math*
 *
 *
 *def fact(n) : # def of factorial function.*
 *if n  0 :*
 *   return n * fact(n-1)*
 *if n == 0 :*
 *   return 1*
 *
 *
 *k = 0*
 *tot = 0*
 *temp1 = 0*
 *while k = 0 and temp1 == 0 :*
 *
 *
 *  a = ( 2 * math.sqrt(2) ) / 9801 # first term before sigma *
 *  nu = fact (4*k) * (1103 + (26390*k) )  # numerator of series*
 *  de = pow( fact(k), 4 ) * pow ( 396, 4*k )  # denominator of series*
 *  *
 *  if de / nu  1e-15 : *
 *temp = nu / de*
 *tot = tot + temp*
 *temp1 = 0 *
 *k = k + 1 *
 *  elif de / nu  == 1e-15 :*
 * series = a * tot  *
 * k = k + 1*
 * temp1 = 0*
 *  elif de / nu  1e-15 :*
 * print series*
 * temp1 = 1*


 I am getting the following error : which is completely surprising!

 *Traceback (most recent call last):*
 *  File pi.py, line 30, in module*
 *print series*
 *NameError: name 'series' is not defined*

 *
 *
 Thus I have removed name 'series' and replaced with  *a*tot, *
 now I am getting this error

 *Traceback (most recent call last):*
 *  File pi.py, line 30, in module*
 *print 1 / (a * tot)*
 *ZeroDivisionError: float divisio*n



 Thus I changed the first highlighted lines to

  *nu = float (fact (4*k) * (1103 + (26390*k) ) )*
 *  de = float (pow( fact(k), 4 ) * pow ( 396, 4*k )) *


 now I am getting

 * Traceback (most recent call last):*
 *  File pi.py, line 18, in module*
 *de = float (pow( fact(k), 4 ) * pow ( 396, 4*k ) )*
 *OverflowError: long int too large to convert to float*

 *help me out of this problem, how could I fix this*

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




I am getting the following error : which is completely surprising!


You only define series when nu/de == XXX. Just don't print series outside
of where it is defined, or print it outside of the while loop if you can be
assured it is defined when the while loop ends.

Even so, you would still end up with the overflow error, because you have de
/ nu and I'm assuming you want nu / de. As an aside, you might want to
consider creating a variable above all the if statements called nude = nu /
de and replace all of the nu / de 's to nude. This way you only divide once
and not (potentially) three times per loop.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] getting error while solving a series that estimates the value of pi

2011-07-18 Thread surya k
Let me write the code again..
Thanks for your help.

On Mon, Jul 18, 2011 at 10:38 PM, James Reynolds eire1...@gmail.com wrote:



 On Mon, Jul 18, 2011 at 12:10 PM, surya k sur...@live.com wrote:

 Hi,

 The problem is to estimate the value of pi using the following series.
  *1 / pi  = (( 2 * sqrt(2) )/ 9801 )  * SIGMA of k[ (4k)! (1103 +
 26390*k) / (k!^ 4 ) * 396^(4k)  ]*
 *where k is [0, infinity)*
 * Problem is located at : ThinkPython Book, www.thinkpython.org
*Pg 89, Exercise 7.5, Think Python Book. *
 *
 *
 the series should be considered till the last term of the sigma must be 
 1e-15
 I have written the below code :

 *# program estimates the value of pi*
 *# Ramanujan's series... *
 *import math*
 *
 *
 *def fact(n) : # def of factorial function.*
 *if n  0 :*
 *   return n * fact(n-1)*
 *if n == 0 :*
 *   return 1*
 *
 *
 *k = 0*
 *tot = 0*
 *temp1 = 0*
 *while k = 0 and temp1 == 0 :*
 *
 *
 *  a = ( 2 * math.sqrt(2) ) / 9801 # first term before sigma *
 *  nu = fact (4*k) * (1103 + (26390*k) )  # numerator of series*
 *  de = pow( fact(k), 4 ) * pow ( 396, 4*k )  # denominator of series
 *
 *  *
 *  if de / nu  1e-15 : *
 *temp = nu / de*
 *tot = tot + temp*
 *temp1 = 0 *
 *k = k + 1 *
 *  elif de / nu  == 1e-15 :*
 * series = a * tot  *
 * k = k + 1*
 * temp1 = 0*
 *  elif de / nu  1e-15 :*
 * print series*
 * temp1 = 1*


 I am getting the following error : which is completely surprising!

 *Traceback (most recent call last):*
 *  File pi.py, line 30, in module*
 *print series*
 *NameError: name 'series' is not defined*

 *
 *
 Thus I have removed name 'series' and replaced with  *a*tot, *
 now I am getting this error

 *Traceback (most recent call last):*
 *  File pi.py, line 30, in module*
 *print 1 / (a * tot)*
 *ZeroDivisionError: float divisio*n



 Thus I changed the first highlighted lines to

  *nu = float (fact (4*k) * (1103 + (26390*k) ) )*
 *  de = float (pow( fact(k), 4 ) * pow ( 396, 4*k )) *


 now I am getting

 * Traceback (most recent call last):*
 *  File pi.py, line 18, in module*
 *de = float (pow( fact(k), 4 ) * pow ( 396, 4*k ) )*
 *OverflowError: long int too large to convert to float*

 *help me out of this problem, how could I fix this*

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




 I am getting the following error : which is completely surprising!


 You only define series when nu/de == XXX. Just don't print series outside
 of where it is defined, or print it outside of the while loop if you can be
 assured it is defined when the while loop ends.

 Even so, you would still end up with the overflow error, because you have
 de / nu and I'm assuming you want nu / de. As an aside, you might want to
 consider creating a variable above all the if statements called nude = nu /
 de and replace all of the nu / de 's to nude. This way you only divide once
 and not (potentially) three times per loop.











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