Post Reply 
Help with HP Prime Python Documentation
10-04-2021, 08:32 PM
Post: #4
RE: Help with HP Prime Python Documentation
(10-04-2021 06:57 PM)Namir Wrote:  Thank you Gunter. I have been using Python on the TI NSpire CAS emulator and it works well. I write numerical analysis code and copy-and-run various sorting algorithms from the internet. I appreciate sample code that shows me how to include Python source code and then launch it!

Namir

Preface: don't rely on what I say, I'm an amateur. But let's give it a try. I've changed my benchmark code a little to avoid the hassle with sys.argv

Code:
#PYTHON name
from math import *
import hpprime
t=hpprime.eval("time")
c=int(input("Enter the exponent! "))
print("Exponent = ",c)
print("Iterations = ", 10**c)
a=0
for i in range(1, 10**c+1):
    a=a+pow((e**(sin(atan(i)))),1/3) 
print("Time (sec) = ",round(hpprime.eval("time")-t,4))
print("Sum = ",a)
#end
Export sums(c)
Begin
  PYTHON(name, c);
End;

with [Shift][1][New] create a new program e.g. sums, delete the template that is in it, copy and paste the code above.

Now from the program catalog run this program. Disregard the input field and touch OK. Now it asks for an exponent, enter e.g. 5 and your done.

Alternatively, create a new APP. Save the Python App under a new name e.G. "Sums"
Open its ("Sums") source code editor by touching [Symb]. Copy the following part of the code
Code:

from math import *
import hpprime
t=hpprime.eval("time")
c=int(input("Enter the exponent! "))
print("Exponent = ",c)
print("Iterations = ", 10**c)
a=0
for i in range(1, 10**c+1):
    a=a+pow((e**(sin(atan(i)))),1/3) 
print("Time (sec) = ",round(hpprime.eval("time")-t,4))
print("Sum = ",a)
into your new App "Sums". Now you can run this app from the Apps screen. And this APP is ready to receive all the bells and whistles you might imagine Smile

Günter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Help with HP Prime Python Documentation - Guenter Schink - 10-04-2021 08:32 PM



User(s) browsing this thread: 1 Guest(s)