Readme

You might also like

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 3

Py4Calc for HP 49/50

What is it? Py4Calc is a translator/compiler program for the hp48GII/hp49/hp50g handheld graphing calculators (and possibly other calculators that support hpbasic and userrpl). Why program in Py4Calc? Py4Calc is designed to run simple python script files with little or no modification (transfer python files from calc to pc or pc to calc!) Python is a very popular standard programming language that can work on any computer, and even some cell phones and other mobile devices. Python indentation means you don't need to add an end or next at the end of a loop. This makes code smaller and easier to read and understand on a small screen. Py4Calc code is written as text in the calculator, which compiles directly to runnable code right on the calculator! You can directly run or debug this output program like any other hp calc program. The Py4Calc translator/compiler program is made in standard userrpl, so it shouldn't crash the calculator like sysrpl or assembly programs might. You can use standard hpbasic commands, for example: MSGBOX(INPUT(MESSAGE,)). You can also insert userrpl commands in Py4Calc, using RPL to start the line. For example: RPL SQ SWAP SQ + Py4Calc supports use of comments, just add #comment to explain your code. Py4Calc supports many of the most popular commands in the Python language: Python for <variable> in range(<num>): for <variable> in range(<num>,<num>): for <variable> in range(<num>,<num>,<num>): while <expression>: ... if <expression>: elif <something>: else: ... print <something> Py4Calc Works same as in Python. The for loop must have only one ( and one ), and 0,1, or 2 commas. Same. Same, it converts to userrpl CASE statement.

Same, but only supports one print at a time. (No print a,b,c) Also, you can't use % to insert variable in the print statement. The calculator will print to the stack. \, \\, and \n escape characters have the same effect in Py4Calc.

Variable = <expression> Variable += <expression> Variable *= <expression>

Same, but only one assignment per line is supported. No a, b = 1, 2

Variable /= <expression> Variable -= <expression> + - / * % (mod), ** (power) !=, ==, <, >, <=, >=, and, or, not math.sin, math.cos ... random.random() round(num,digits) repr(, long( Math.factorial, math.sqrt(, math.e, math.pi, math.fabs, sum(, sorted(, ord, math.exp(, math.ceil, math.floor, math.log, math.log10 unichr(num), chr(num) variable=text string Same Same Same, converted to built-in functions. Same, automatically changed to RAND. Same, automatically changed to TRNC. Same, automatically changed to STR. Same, automatically changed to builtin function.

Same, automatically changed to CHR(. Only double quoted text works. Any valid variable name should work. Using strings or variables containing if, while, or other reserved words may mix up the translator and result in errors. For best results, use userrpl for this. (For example: RPL textwithif:while:for:andothertext. VARIABLENAME STO) Not implemented, you'll have to find the userrpl command for it.

Def functionname():, import <module>, string.<function>, array.<function> and many others... Examples: Python Show combinations of 2 dice where one is 6: for a in range(1,7): for b in range(1,7): if A==6 or B==6: print A,B

Py4Calc for A in range(1,7): for B in range(1,7): if A==6 or B==6: print A print B # This next line is rpl inside Py4Calc! RPL 2 LIST

Find factorial of the user's input number: Out = 1 Out=1 A = STR(INPUT(NUM=,)) A=long(raw_input(num=)) while A>1: while (A>1.) out=out*a out=out*a a = a-1 a=a-1 print out print out Some examples are based on this. More examples are in the PYEXAMPLES.hp file.

Installing and using:


This guide assumes RPN mode on your calculator, though algebraic mode may work fine. You'll need a calculator and transfer cable (or sd and sd card reader), or an hp emulator to run this program. To connect your computer to the calculator, you need a cable and software installed to use it. To run the program on the computer, you can use the free Emu48. Start an on-screen hp49 or hp50 calculator, then load the program with Edit menu, Load object. For help on transferring and installing calculator software, see http://www.hpcalc.org/install.php. There are 2 ways to get Py4Calc installed on the calculator: 1. Install the library This is the easiest way to run it, and you can always get to Py4Calc with rightshift-LIB, PyCalc. You should be able to install this to any port. If you install to port 2 it shouldn't get deleted if the calculator crashes. To install: 1. Transfer the library file to your calculator home directory. 2. Press the VAR key and press the button in the upper row of the keypad that is below the program variable. Now you'll see a Library: 1256 at the bottom of the screen. 3. Press 2 STO or 0 STO to put in port 2 or 0. 4. Hold ON (or right click in emu48) and press C to restart. 2. Copy the source Do this if you want to debug this program or view the source. This should run at the same speed as the library version, but the program might get changed or deleted accidentally, and it will take up memory in home. 1. Remove the library if installed. 2. Transfer the sourcecode.hp file to the calculator, and recall it to the stack. 3. run the STR command. Type 'PYTHON' STO and it will make a new directory called PYTHON, with the source files in it. 4. To use the program, go to VARS and select the PYTHON directory. You need to be in this directory to run this. 5. Documentation on how this program works can be found in HPCode-explained.txt. To use Py4Calc, type ENTER, then press down key to edit the text string, and type in your program in the text editor. Press enter twice to make a copy, then run PYC to convert it to a program. If you have problems... If you get a STR error when you run PYC, it is probably a syntax error in your program, or possibly a bug in Py4Calc. Press down arrow to edit the string, then copy all the text (rightshiftdown, rightshift end, rightshift copy, ON/cancel), and paste and enter it in the main stack, then the calculator should highlight the bad code. If you still have problems, check the original python code for errors, such as missing : at the end of if/while/for lines. If you need to make a program run on the older HP48 calculators, run the HP48 command on the program. This tries to make the program runnable on hp48 and hp49/50. If you have problems running a program made with Py4Calc in algebraic mode, try running CASCFG. If that doesn't fix it, check the output code and the original code to see if there is an error somewhere. Maybe there is an unsupported command, like raw_input, or file.open.

You might also like