Help with HP Prime Python Documentation
10-05-2021, 06:49 AM
Post: #6
 toml_12953 Senior Member Posts: 1,855 Joined: Dec 2013
RE: Help with HP Prime Python Documentation
(10-04-2021 08:32 PM)Guenter Schink Wrote:
(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

Günter

Do you really want to set the starting time before the input statement? That won't just time the machine, it'll include the time it takes for you to answer the question as well.

Tom L
Cui bono?
 « Next Oldest | Next Newest »

 Messages In This Thread Help with HP Prime Python Documentation - Namir - 10-04-2021, 12:08 PM RE: Help with HP Prime Python Documentation - Guenter Schink - 10-04-2021, 03:46 PM RE: Help with HP Prime Python Documentation - Namir - 10-04-2021, 06:57 PM RE: Help with HP Prime Python Documentation - Guenter Schink - 10-04-2021, 08:32 PM RE: Help with HP Prime Python Documentation - toml_12953 - 10-05-2021 06:49 AM RE: Help with HP Prime Python Documentation - Guenter Schink - 10-05-2021, 06:27 PM RE: Help with HP Prime Python Documentation - Namir - 10-05-2021, 05:59 AM RE: Help with HP Prime Python Documentation - Namir - 10-05-2021, 09:13 PM RE: Help with HP Prime Python Documentation - Guenter Schink - 10-05-2021, 10:10 PM

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