Popular recipes tagged "numbers" but not "python"http://code.activestate.com/recipes/tags/numbers-python/2017-03-12T23:10:48-07:00ActiveState Code RecipesNumber of bits needed to store an integer, and its binary representation (Python) 2017-03-12T23:10:48-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580762-number-of-bits-needed-to-store-an-integer-and-its-/ <p style="color: grey"> Python recipe 580762 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/integers/">integers</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/representation/">representation</a>, <a href="/recipes/tags/type/">type</a>). </p> <p>This recipe shows how to find, via Python code, the number of bits needed to store an integer, and how to generate its binary representation. It does this for integers from 0 to 256.</p> <p>More details and full output here:</p> <p><a href="https://jugad2.blogspot.in/2017/03/find-number-of-bits-needed-to-store.html" rel="nofollow">https://jugad2.blogspot.in/2017/03/find-number-of-bits-needed-to-store.html</a></p> Roman Numeral Converter (Python) 2016-12-13T05:05:52-08:00Brandon Martinhttp://code.activestate.com/recipes/users/4194238/http://code.activestate.com/recipes/580731-roman-numeral-converter/ <p style="color: grey"> Python recipe 580731 by <a href="/recipes/users/4194238/">Brandon Martin</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/numerals/">numerals</a>, <a href="/recipes/tags/roman/">roman</a>). </p> <p>Provides two functions: romanToNumber - Converts a string of Roman Numerals (I,V,X,L,C,D,M) into an integer. (ignores formatting, will return best guess if improperly formatted) numberToRoman - Converts an integer into a string of Roman Numerals</p> Generate a set of random integers (Python) 2016-02-18T19:34:17-08:00Lance Spencehttp://code.activestate.com/recipes/users/4193647/http://code.activestate.com/recipes/580613-generate-a-set-of-random-integers/ <p style="color: grey"> Python recipe 580613 by <a href="/recipes/users/4193647/">Lance Spence</a> (<a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/random/">random</a>). </p> <p>This is just a short and simple script that generates a set of random numbers. You enter how many random numbers you want and the program will generate them.</p> <p>The num is multiplied by 10 in the upper limit within the for loop to give you larger generated integers. Adjust it as needed.</p> Averaging Literal Numbers (Python) 2012-12-06T13:44:42-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578365-averaging-literal-numbers/ <p style="color: grey"> Python recipe 578365 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/numbers/">numbers</a>). </p> <p>One program that a teacher may assign to beginning programming students would be to take a list of numbers and average them together. This recipe does just that and is designed to be easy to read and follow, showing what is possible with a few lines of Python.</p> primeList (Python) 2011-11-05T23:42:37-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577935-primelist/ <p style="color: grey"> Python recipe 577935 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primelist/">primelist</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/theory/">theory</a>). Revision 3. </p> <p>This module returns all the prime numbers strictly less than n. For this code to print out all of the primes n inclusive, in the range, n+1 must be substituted for n.</p> "Comma float" to float (Python) 2010-02-11T22:19:41-08:00Matevz Leskohttp://code.activestate.com/recipes/users/4173032/http://code.activestate.com/recipes/577054-comma-float-to-float/ <p style="color: grey"> Python recipe 577054 by <a href="/recipes/users/4173032/">Matevz Lesko</a> (<a href="/recipes/tags/comma/">comma</a>, <a href="/recipes/tags/float/">float</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/string/">string</a>). Revision 2. </p> <p>Convert comma separated floating point number (12,3456) to float.</p> RomanNumeral to Integers (viceversa) (Java) 2010-07-18T11:20:19-07:00st0lehttp://code.activestate.com/recipes/users/4174421/http://code.activestate.com/recipes/577313-romannumeral-to-integers-viceversa/ <p style="color: grey"> Java recipe 577313 by <a href="/recipes/users/4174421/">st0le</a> (<a href="/recipes/tags/conversions/">conversions</a>, <a href="/recipes/tags/java/">java</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/roman/">roman</a>). </p> <p>Converts Roman Symbols to Integers and back.</p> Infinite list of primes! Yay! (Python) 2010-07-20T04:05:00-07:00Alejandro Peraltahttp://code.activestate.com/recipes/users/4174433/http://code.activestate.com/recipes/577318-infinite-list-of-primes-yay/ <p style="color: grey"> Python recipe 577318 by <a href="/recipes/users/4174433/">Alejandro Peralta</a> (<a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/primes/">primes</a>). </p> <p>It's an iterator that returns prime numbers. </p> <p>Got the idea from here: <a href="http://www.cs.hmc.edu/%7Eoneill/papers/Sieve-JFP.pdf" rel="nofollow">www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf</a></p> Prime, Perfect and Fibonacci Number Widget Class (Python) 2010-05-19T17:02:28-07:00AJ. Mayorgahttp://code.activestate.com/recipes/users/4173476/http://code.activestate.com/recipes/577229-prime-perfect-and-fibonacci-number-widget-class/ <p style="color: grey"> Python recipe 577229 by <a href="/recipes/users/4173476/">AJ. Mayorga</a> (<a href="/recipes/tags/cryptography/">cryptography</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primes/">primes</a>). Revision 2. </p> <p>A class Ive had in my snippets for awhile that can generate prime, perfect and fibonacci sequences as well as check whether or not a supplied value is any of them.</p> format a number as an ordinal (Python) 2010-02-04T12:54:27-08:00Serdar Tumgorenhttp://code.activestate.com/recipes/users/4171495/http://code.activestate.com/recipes/576888-format-a-number-as-an-ordinal/ <p style="color: grey"> Python recipe 576888 by <a href="/recipes/users/4171495/">Serdar Tumgoren</a> (<a href="/recipes/tags/number/">number</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/numerals/">numerals</a>, <a href="/recipes/tags/ordinals/">ordinals</a>). Revision 10. </p> <p>This function converts 0 and <em>positive</em> integers (or their string representations) to their ordinal values. For example, it would convert 0 to "0th", 1 to "1st", 2 to "2nd", 3 to "3rd" and so on.</p> Simple primes generator (Python) 2009-11-04T06:52:06-08:00Maxime Fontenierhttp://code.activestate.com/recipes/users/4172150/http://code.activestate.com/recipes/576948-simple-primes-generator/ <p style="color: grey"> Python recipe 576948 by <a href="/recipes/users/4172150/">Maxime Fontenier</a> (<a href="/recipes/tags/any/">any</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/primes/">primes</a>). </p> <p>Simple prime generator. </p> <p>I write it as a sample usage of the any function.</p> num2words (Python) 2012-11-28T19:41:07-08:00khttp://code.activestate.com/recipes/users/4168241/http://code.activestate.com/recipes/576577-num2words/ <p style="color: grey"> Python recipe 576577 by <a href="/recipes/users/4168241/">k</a> (<a href="/recipes/tags/num2words/">num2words</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/numerals/">numerals</a>). Revision 3. </p> <p>A simple python script that translates an integer to plain English.</p> format a number for human consumption (Python) 2008-07-29T07:06:58-07:00Pádraig Bradyhttp://code.activestate.com/recipes/users/1890175/http://code.activestate.com/recipes/576385-format-a-number-for-human-consumption/ <p style="color: grey"> Python recipe 576385 by <a href="/recipes/users/1890175/">Pádraig Brady</a> (<a href="/recipes/tags/format/">format</a>, <a href="/recipes/tags/iec/">iec</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/si/">si</a>, <a href="/recipes/tags/thousands/">thousands</a>). </p> <p>convert a number to a string representation that is more easily parsed by humans. It supports inserting thousands separators and converting to IEC or SI units.</p>