Professional Documents
Culture Documents
Readme
Readme
Readme
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> + - / * % (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.