print() in CAS Program
|
04-20-2021, 03:09 PM
(This post was last modified: 04-20-2021 03:09 PM by toml_12953.)
Post: #1
|
|||
|
|||
print() in CAS Program
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? Tom L Cui bono? |
|||
04-20-2021, 03:43 PM
(This post was last modified: 04-20-2021 04:42 PM by StephenG1CMZ.)
Post: #2
|
|||
|
|||
RE: print() in CAS Program
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. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
04-20-2021, 03:43 PM
Post: #3
|
|||
|
|||
RE: print() in CAS Program
I don't have the beta installed so i can't test it, but maybe try:
print(EXPR(t + " seconds")); -road |
|||
04-20-2021, 05:23 PM
(This post was last modified: 04-20-2021 05:26 PM by toml_12953.)
Post: #4
|
|||
|
|||
RE: print() in CAS Program
(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. Curious. PRINT(t+" seconds") works but print(t+" seconds") doesn't. Tom L Cui bono? |
|||
04-20-2021, 05:29 PM
Post: #5
|
|||
|
|||
RE: print() in CAS Program
(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. print(str(t)+" seconds") prints str(t)+" seconds" Tom L Cui bono? |
|||
04-20-2021, 05:33 PM
Post: #6
|
|||
|
|||
RE: print() in CAS Program
(04-20-2021 03:43 PM)roadrunner Wrote: I don't have the beta installed so i can't test it, but maybe try: The output is EXPR(t + " seconds") Tom L Cui bono? |
|||
04-20-2021, 05:55 PM
(This post was last modified: 04-20-2021 06:21 PM by StephenG1CMZ.)
Post: #7
|
|||
|
|||
RE: print() in CAS Program
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? Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
04-20-2021, 06:42 PM
Post: #8
|
|||
|
|||
RE: print() in CAS Program
(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. You're quite right. The PPL PRINT() works in the CAS program but the print() fails. Tom L Cui bono? |
|||
04-21-2021, 12:42 PM
Post: #9
|
|||
|
|||
RE: print() in CAS Program
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. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)