Jody Crothers
Head of Learning Area (Mathematics)
Ridge View Secondary College
Western Australia
With best wishes,
Steve
_________________
Steve Arnold
Phone: +(61)4 0175 3834
_________________
I love that talking about primes gets Steve to participate 😊
I now know Steve’s bat-signal 😊
Hi, Steve!
(btw, I recently learned about “emirp” numbers and love all the love for primes 😊)
To the original question:
Jody – Python doesn’t have a built-in isPrime() function. Yeah, I know…. 😐
But thanks to Steve’s fun-looking formula, we have one now.
Here’s the code and I have attached the TNS
from math import *
def factorial(n):
if n == 1:
return 1
else:
return n*factorial(n-1)
def isPrime(n):
retval = floor(cos(pi*((factorial(n-1))+1)/(n))**2)
return retval;
for i in range(2, 10):
print(i, "Prime:?", isPrime(i))
Hope this helps,
- Harshal
From: ti-inn...@googlegroups.com <ti-inn...@googlegroups.com>
On Behalf Of Stephen Arnold
Sent: Monday, October 14, 2024 10:43 PM
To: TI-Innovator for Education <ti-inn...@googlegroups.com>
Subject: [EXTERNAL] Re: isPrime in Python
(Not sure if previous reply got through - it has been a while!) Hey Jody Greetings from the east coast, land of retirement! Sadly, I haven’t had the chance to get into Python as yet, so cannot answer your question directly. However, in my free
ZjQcmQRYFpfptBannerStart
|
ZjQcmQRYFpfptBannerEnd
--
You received this message because you are subscribed to the Google Groups "TI-Innovator for Education" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ti-innovator...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ti-innovator/e4290039-bf9c-486c-bff3-39329ad6029fn%40googlegroups.com.
With best wishes,
Steve
_________________
Steve Arnold
Phone: +(61)4 0175 3834
_________________
def isPrime(n):
if n<2:
return False
a=int(n**0.5+1)
for i in range(2,a):
if n%i == 0:
return False
return True
n=10756073
print(isPrime(n))
Best Wishes,
Bert
--
You received this message because you are subscribed to the Google Groups "TI-Innovator for Education" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ti-innovator...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/SL2P216MB1048D1F1767A2A3079D2137EB8452%40SL2P216MB1048.KORP216.PROD.OUTLOOK.COM.
That’s my preference:
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/CDFD5FEB-08F9-4180-A9AD-1E118EAC36E6%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/053a01db2079%247e9b9a20%247bd2ce60%24%40gmail.com.
Jody Crothers
Head of Learning Area (Mathematics)
Ridge View Secondary College
Western Australia
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/6DFD8D4D-E767-4599-A51B-5BC5B64DD4E6%40t-online.de.
--
You received this message because you are subscribed to the Google Groups "TI-Innovator for Education" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ti-innovator...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/DEDFA62F-778C-4DBB-AB83-82F8118A9E9E%40gmail.com.
<isPrime.tns>
Op 17 okt 2024, om 11:56 heeft Hubert Langlotz <langlotz...@t-online.de> het volgende geschreven:
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/6DFD8D4D-E767-4599-A51B-5BC5B64DD4E6%40t-online.de.
--
You received this message because you are subscribed to the Google Groups "TI-Innovator for Education" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ti-innovator...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/DEDFA62F-778C-4DBB-AB83-82F8118A9E9E%40gmail.com.
Anfang der weitergeleiteten Nachricht:Von: Sebastian Rauh <s-r...@gmx.de>Betreff: Aw: isPrime in PythonDatum: 17. Oktober 2024 um 12:20:52 MESZAn: Hubert Langlotz <langlotz...@t-online.de>Kopie: ti-inn...@googlegroups.comHello @all,there is another way, which is faster. I exported the candidate to a variable in notes, there the calculation with is_prime is done, and reimported the result.I attched a file. In comparison my way is a litte faster, but maybe the construction is not as sturdy as the construction in pure python.Best regardsSebastian
I really love how this discussion moved to effective ways of using TI-Nspire CX II math engine and it’s capabilities to extend TI-Nspire CX II’s Python functionality. :)
Thanks Bert for the two examples!
And we also learned about Willan’s formula and it’s limitations.
It’s a prime example (oof! :) of the depth and breadth of knowledge of this amazing community of educators.
Thanks and regards,
- Harshal
From: ti-inn...@googlegroups.com <ti-inn...@googlegroups.com>
On Behalf Of Bert Wikkerink
Sent: Friday, October 18, 2024 3:22 AM
To: ti-inn...@googlegroups.com
Subject: [EXTERNAL] Re: isPrime in Python
It works with a functions that needs one numerical argument and returns one numerical value. But you can use more arguments by first store them. As an example: Python does not know the gcd function but TI-Nspire does. So you can define a function
ZjQcmQRYFpfptBannerStart
This message was sent from outside of Texas Instruments.
Do not click links or open attachments unless you recognize the source of this email and know the content is safe.
ZjQcmQRYFpfptBannerEnd
It works with a functions that needs one numerical argument and returns one numerical value.
--
You received this message because you are subscribed to the Google Groups "TI-Innovator for Education" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ti-innovator...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/F76FE325-7B64-48A1-8BD2-694E72254A7F%40gmail.com.
.
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/SL2P216MB104894555223BCBC4D350CFEB8472%40SL2P216MB1048.KORP216.PROD.OUTLOOK.COM.
--
You received this message because you are subscribed to the Google Groups "TI-Innovator for Education" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ti-innovator...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/F76FE325-7B64-48A1-8BD2-694E72254A7F%40gmail.com.