The string length is naturally already mentioned by D. Joyner ( len (str(n)) ) But for teaching and other mathematical connections, would it perhaps be better to use the (base 10 logarithm) decimal logarithm to get the number of digits? In python it is ceil(log10(n))
Can be used like this: sage: from math import * sage: n=123456789900000101202030405066778888 sage: ceil(log10(n)) 36.0 Ladislav Kocbach (University of Bergen, Norway) On Sep 19, 4:14 pm, calcp...@aol.com wrote: > Sorry, silly question: > > OK, I know I've done this in Sage before, but I can't remember for the > life of me how. > > I'm writing a program that computes large integers and tests for > primality. What I'd like to do is print out the integer and how many > digits it has. I seem to remember having to convert the integer to a > string and then find its length() or size(). > > Could someone please remind me how this works? > > TIA, > A. Jorge Garciahttp://calcpage.tripod.com > > Teacher & Professor > Applied Mathematics, Physics & Computer Science > Baldwin Senior High School & Nassau Community College --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sage-edu" group. To post to this group, send email to sage-edu@googlegroups.com To unsubscribe from this group, send email to sage-edu+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-edu?hl=en -~----------~----~----~----~------~----~------~--~---