new user python on hp prime g2, casio cg50 - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: new user python on hp prime g2, casio cg50 (/thread-16995.html) |
new user python on hp prime g2, casio cg50 - Liamtoh Resu - 05-23-2021 05:51 PM I am trying to get a simple hello world python program onto the prime g2. I have read the post: "https://www.hpmuseum.org/forum/thread-16950.html"" The post mentions a DevKit. Where can I get it? Also, once I get the program onto the prime, how do I launch/run it. BTW: The casio cg-50 has upfront file, run, open, shell, ... commands built into its micropython environment. Thanks. RE: new user python on hp prime g2, casio cg50 - Liamtoh Resu - 05-24-2021 03:52 PM The python shell on the prime works fine as a calculator. eg. s = 100 a = 21 b = 5 c = a + b t = s - c t c === I put the following on the cg50 which i can run on the casio and from a windows cmd line shell via "python test0004.py". # 20190704 casio cg50 # micro python # print string array # test0004.py import math j=3 a=['moe','larry','curly'] print (j) print (a) for j in range(3): x=a[j] print (x) === This blog post does not present the indentation of the python source code of the last two lines, x=a[j], print(x). === Is there a way to put this program into the prime via the prime hp connectivity kit and then run it from the prime? Thanks. RE: new user python on hp prime g2, casio cg50 - toml_12953 - 05-24-2021 05:11 PM (05-24-2021 03:52 PM)Liamtoh Resu Wrote: I put the following on the cg50 which i can run on the casio Yes, you can write the program like this: Code: #PYTHON(name) Then copy it to the programs folder in the CK. You can run it like an HPPL program from the menu. You can put your code between code tags (# in the list) to preserve the indentation. RE: new user python on hp prime g2, casio cg50 - Liamtoh Resu - 05-24-2021 05:56 PM Thanks Tom for your help. I put the edited code into the prime, but I am still having problems. I did the following. ) launched Python ) pressed <shift> <programs> ) selected test0004 ) pressed the Run tab The prime presented the yellow exclamation mark. I double checked the source file. Thanks again. RE: new user python on hp prime g2, casio cg50 - toml_12953 - 05-24-2021 06:56 PM (05-24-2021 05:56 PM)Liamtoh Resu Wrote: Thanks Tom for your help. In my example, you don't launch Python. Go to the Functions Home screen then press Shift-1. Select test0004 from the menu and press enter. That's the same way as you launch a regular HPPL program. RE: new user python on hp prime g2, casio cg50 - Liamtoh Resu - 05-24-2021 09:46 PM I still can not get your edited code to run. I reflashed the prime g2 with the 20210505 update--same result. I have the revision D hardware. Is there a subtle setting(s) change in the prime to be done to get it working? Thanks. RE: new user python on hp prime g2, casio cg50 - toml_12953 - 05-25-2021 02:26 AM (05-24-2021 09:46 PM)Liamtoh Resu Wrote: I still can not get your edited code to run. Oops! My fault. Try this: Code: #PYTHON name RE: new user python on hp prime g2, casio cg50 - Liamtoh Resu - 05-25-2021 03:47 AM And that finally worked! Thank you very much. Incidently, I am a new blog user. I was wondering how to create the scrollable source code boxes and how to put the quoted text boxes into white boxes on this blog site. Thanks! RE: new user python on hp prime g2, casio cg50 - Thomas_Sch - 05-25-2021 05:38 AM (05-25-2021 03:47 AM)Liamtoh Resu Wrote: ..Please have a look at the attached pic. RE: new user python on hp prime g2, casio cg50 - Liamtoh Resu - 05-25-2021 06:12 AM Thanks for the tip on on the toolbar just below and extending to the right of the font and text size changers. . RE: new user python on hp prime g2, casio cg50 - drbarnack - 05-26-2021 06:28 AM Following on this, is there a way to return the output from a Python script embedded in a PPL program to the stack? For example, this program will print the output to the Terminal: Code:
Is there a way of returning 4 instead of 0 as shown in the screenshot? -DrBarnack RE: new user python on hp prime g2, casio cg50 - Liamtoh Resu - 05-26-2021 06:42 PM There are several things going on there. ) The use of "y = sqrx(sys.argv[0])" rather than a standard python input statement. I was surprised (positively) that an input form line was presented. ) The intended square was presented on the terminal screen rather instead of being returned as a return value. ) If the python environment accepts the C-style input maybe there is a C-style output statement. RE: new user python on hp prime g2, casio cg50 - Liamtoh Resu - 05-27-2021 03:04 AM I tweaked your program a bit. I don't know if this was your intent. Code:
Sorry, I just condensed the white space. I was trying variations on the prime g2 for a long while trying different variations. I don't know if hp prime g2 prime python can return pointers to sys.arg[0]. RE: new user python on hp prime g2, casio cg50 - drbarnack - 05-29-2021 08:09 AM (05-26-2021 06:28 AM)drbarnack Wrote: Following on this, is there a way to return the output from a Python script embedded in a PPL program to the stack? I figured this out. The trick is to evaluate the output from the Terminal: Code:
This takes a value from the stack ("sys.argv[0]"), does the calculation in Python, prints the answer to the Terminal, parses the first string in the Terminal into an expression and evaluates it, leaving the answer on the stack for future use ("RETURN EXPR(TERMINAL(1));"). So in Home or CAS mode I can use Python scripts like any other function in the Toolbox to manipulate values. RE: new user python on hp prime g2, casio cg50 - Liamtoh Resu - 05-30-2021 10:15 PM Editing text with the new 20210428 beta connectivity kit seems to have solved the problem of sending extra characters along with source code. I had to install the 20210428 beta on top of the 2020 CK. The beta software failed to run with an uninstall old software and then installing the beta. Clicking on the retro 3.5 disk icon saves the program onto the prime. The 2020 CK would show a simpler text window with a prompt to save the program. RE: new user python on hp prime g2, casio cg50 - Liamtoh Resu - 06-02-2021 08:42 PM At this point after 20 days of using the prime g2, I have decided to slog through chapter 29 of the 2018 user guide ( just like I did with the K&R 30 years ago). I am most fortunate to have a laser printer that does duplex printing. There will be a PPL version of the small python program referred to in this thread. Thanks again to Tom L and others. RE: new user python on hp prime g2, casio cg50 - Ioncubekh - 10-20-2022 11:21 PM @drbarnack Quote:This takes a value from the stack ("sys.argv[0]"), does the calculation in Python, prints the answer to the Terminal, parses the first string in the Terminal into an expression and evaluates it, leaving the answer on the stack for future use ("RETURN EXPR(TERMINAL(1));"). So in Home or CAS mode I can use Python scripts like any other function in the Toolbox to manipulate values. Excellent explanation! Kindly tell what is this Terminal(1) what is this variable? |