HP Forums
print() in CAS Program - 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: print() in CAS Program (/thread-16702.html)



print() in CAS Program - toml_12953 - 04-20-2021 03:09 PM

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?


RE: print() in CAS Program - StephenG1CMZ - 04-20-2021 03:43 PM

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.


RE: print() in CAS Program - roadrunner - 04-20-2021 03:43 PM

I don't have the beta installed so i can't test it, but maybe try:

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

-road


RE: print() in CAS Program - toml_12953 - 04-20-2021 05:23 PM

(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.


RE: print() in CAS Program - toml_12953 - 04-20-2021 05:29 PM

(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"


RE: print() in CAS Program - toml_12953 - 04-20-2021 05:33 PM

(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")


RE: print() in CAS Program - StephenG1CMZ - 04-20-2021 05:55 PM

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?


RE: print() in CAS Program - toml_12953 - 04-20-2021 06:42 PM

(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.


RE: print() in CAS Program - jonmoore - 04-21-2021 12:42 PM

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.