MarcPerezPro/HP-PRIME-BLACK-SCHOLES-MERTON

Python Coding

Closed this issue · 4 comments

With latest firmware Python is enabled in HP Prime. I have some question regarding it. Will you help

Hi @defencedog
Unfortunately I haven't tried the Python interpreter on my HP Prime G2.
But I'm sure it's way easier to program than HP PPL, and there are plenty of Python tutorials online.
Just remember that you can't use any fancy library, so you're going to spend some time reinventing the wheel.

@return-main I just want to know if variables can somehow shared between python & PPL. I mean say my python returns a list in a variable how can I assign it to HP Prime native L1 list variable for plots & stuff

@defencedog I'm sorry for the delay, I was busy organizing my marriage 👰‍♂️

This was much harder than expected, but I made you a proof of concept:
https://gist.github.com/return-main/b7071adad860a300fd07ad51cc54fe80

#PYTHON PY_RANGE
import sys
var_from = int(sys.argv[0])
var_to = int(sys.argv[1])
l=list(range(var_from,var_to))
print("{"+str(l)[1:-1]+"}")
#END

EXPORT RANGE(var_from,var_to)
BEGIN
  // clear the Terminal
  PRINT;
  // run the Python script
  PYTHON(PY_RANGE,var_from,var_to);
  // evaluate the string in the Terminal and return to the stack
  RETURN EXPR(TERMINAL(1));
END;

@return-main Extremely Thanks & Congratz on your marriage.

Your idead is very welcome. I have experimented with python greatly & you can visit my playground
https://github.com/defencedog/HP-Prime-Advance/tree/main/Scripts_Python