HP Forums

Full Version: print() in CAS Program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to use print() in a CAS program that uses Python syntax. I'm pretty sure it worked before the Apr 16 beta.

t = 4
print(t + " seconds")

should print

4 seconds

instead it prints

t + " seconds"

How can I get it to print the value of t rather than the entire string in the parentheses?
In actual Python, “+” isn’t defined between strings and numerical, so in Python you would use (str(t)+” seconds”) to turn t into a string.
I assume that the Python beta should be the same (if implemented).

The Python-syntax-in-CAS in the existing product? Not sure.
I don't have the beta installed so i can't test it, but maybe try:

print(EXPR(t + " seconds"));

-road
(04-20-2021 03:43 PM)StephenG1CMZ Wrote: [ -> ]In actual Python, “+” isn’t defined between strings and numerical, so in Python you would use (str(t)+” seconds”) to turn t into a string.
I assume that the Python beta should be the same (if implemented).

The Python-syntax-in-CAS in the existing product? Not sure.

Curious.

PRINT(t+" seconds")
works but
print(t+" seconds")
doesn't.
(04-20-2021 03:43 PM)StephenG1CMZ Wrote: [ -> ]In actual Python, “+” isn’t defined between strings and numerical, so in Python you would use (str(t)+” seconds”) to turn t into a string.
I assume that the Python beta should be the same (if implemented).

The Python-syntax-in-CAS in the existing product? Not sure.

print(str(t)+" seconds") prints

str(t)+" seconds"
(04-20-2021 03:43 PM)roadrunner Wrote: [ -> ]I don't have the beta installed so i can't test it, but maybe try:

print(EXPR(t + " seconds"));

-road

The output is

EXPR(t + " seconds")
I think what is happening is that the Python-syntax-in-CAS doesn't implement Python's string function.

Anything that Python-in-CAS doesn't understand is being interpreted by the CAS (or the PPL) instead.

For example, you can draw a Mandelbrot set using Python-in-CAS, using PPL's PIXON calls inside the Python for loop. And those PIXON calls are surely PPL and not Python. [can't find that program now]

So, whatever syntax you need within the PRINT is likely to be PPL (or CAS within the print), not Python, unless you are using the Python Beta.

Does that help? Or am I mistaken?
(04-20-2021 05:55 PM)StephenG1CMZ Wrote: [ -> ]I think what is happening is that the Python-syntax-in-CAS doesn't implement Python's string function.

Anything that Python-in-CAS doesn't understand is being interpreted by the CAS (or the PPL) instead.

For example, you can draw a Mandelbrot set using Python-in-CAS, using PPL's PIXON calls inside the Python for loop. And those PIXON calls are surely PPL and not Python. [can't find that program now]

So, whatever syntax you need within the PRINT is likely to be PPL (or CAS within the print), not Python, unless you are using the Python Beta.

Does that help? Or am I mistaken?

You're quite right. The PPL PRINT() works in the CAS program but the print() fails.
I'm not totally certain on this but as I understand things the 'Python' in CAS isn't actually parsed by the MicroPython interpreter but is instead simply a set of Python keywords build into XCAS that translate Python functions into their XCAS variety. On that basis, it can't always be trusted to follow Python conventions.

With Python functioning differently in the CAS, the HP PPL program editor and the actual MicroPython program editor, I can see this leading to lots of confusion once the beta functionality rolls out as the official release.
Reference URL's