I am asking this because I am habitually intrigued by numbers. Python seems to be a good language to explore all sorts of numeric facts. Do you have any 'tricks' hidden away? Here is one about the number 61 I recently bumped into:

Recommended Answers

All 22 Replies

Haven't really used Python to play with numbers, however, I have done a lot of playing around (although not recently) in . I used APL extensively back in my university days (the 70s). It was fun then and fun now. In fact, Python list comprehensions have their roots in APL.

The prime number 37 is very humble, but has some tricks up it sleeves:

Python can handle large integer values without a sweat:

Now put in a really large number such as the number of observeable stars today. That's 200 billion trillion stars (2 × 10²² to 7 × 10²² or more).

commented: Who counted them? +3

Stars in the Universe is close to Avogadro's number N = 6.023 * 10**(23) molecules/mole

SI prefixes (sometimes useful)

yotta = 1e24
zetta = 1e21
exa = 1e18
peta = 1e15
tera = 1e12
giga = 1e9
mega = 1e6
kilo = 1e3
hecto = 1e2
deka = 1e1
deci = 1e-1
centi = 1e-2
milli = 1e-3
micro = 1e-6
nano = 1e-9
pico = 1e-12
femto = 1e-15
atto = 1e-18
zepto = 1e-21

Here is the curious example of the missing number 8 normal and on steroids:

Who counts such things? That would be Count von Count.
With our luck it's the folks in charge of the National Debt!

Who would have thought that the sum of a list of integers could be so predictable?

commented: Now find the routine that always returns 6174 +16

The classic tale about the chess game:

"Now find the routine that always returns 6174"
Here is my Python hack:

commented: Nice practice unit. +0

Some folks like approximations of pi. One person that really used his brains was Srinivasa Ramanujan, doing well! In commemoration of Professor Badii, the giggling professor, whose 4 semesters of advanced calculus I took with joy! May he never miss his curry stew!

This afternoon I will see my kidney doctor, a very fine lady from India. I am sure she is proud of all the great mathematicians that India has produced. Here is a python snippet that converts a number into english words:

Indian mathematicians have nothing to be proud of.

commented: I'm giving you nothing for that comment. +0

Yes to the folks in India and Persia who came up with the decimal system! There must be reason we have ten fingers.
Can you imagine doing even simple accounting with roman numerals?

Indian mathematicians have nothing to be proud of.

Judging by the downvote, at least one person missed the point entirely.

commented: 🧑‍⚖️🧑‍⚖️🧑‍⚖️🧑‍⚖️🧑‍⚖️🧑‍⚖️🧑‍⚖️🧑‍⚖️🧑‍⚖️ +16
commented: Like the play on words nothing=zero +3

Is Python good with numbers?
Here is one test:

IPython 8.20.0 -- An enhanced Interactive Python.
nothing = 0
nothing ** nothing
Out[2]: 1

Python follows convention that anything to the power zero is one.

As some of you might have noticed, I am playing around with the Arduino line of interface boards. Checking out an OLED (Organic Light Emitting Diode) display I used the function millis() in the Arduino IDE that is used to program Arduino boards. This function accesses a stream of integer millisecond values generated by the onboard quarz crystal oscillator.

The standard Arduino IDE runs C++, but can also use MicroPython for boards like the inexpensive 'Arduino Nano ESP32'
// millis() uses unsigned long values
// 0 to 4,294,967,295 (2^32 - 1) or about 50 days in millisec
// after that it will reset to zero and count up again
display.setCursor(0, 0); // ULC column, row in pixels
unsigned long millisec = millis();
unsigned long sec = millisec/1000;
unsigned long min = sec/60;
unsigned long hr = min/60;
...

So my mind is going overtime, mathematically what can you do with a continuous data stream like that?
This one is only possible in the computer-age.

That is a really interesting way to use Python! I am also fascinated by these little number patterns and mathematical tricks. I would definitely love to see the trick you found with 61. Once you share it I can try to find a few similar ones too.

Annie, you might want to take a closer look into how Python handles the concept of "Nothing". For instance "n/0" goes to "infinity", the most opposite of nothing. Is infinity then the inverse of nothing? Give it a thought.

Add two even numbers together and you get an even number
Add two odd numbers together and you get an even number
The only way to get an odd number is to add an even number to an odd one

Would it be logical to say that there are more even numbers than odd once?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.