Post Reply 
Some Python Scripts to understand Variables Transfer
10-26-2022, 02:04 AM (This post was last modified: 10-26-2022 02:06 AM by Eddie W. Shore.)
Post: #4
RE: Some Python Scripts to understand Variables Transfer
I found what was causing the error:

I typed "import math as *" when it should be just "from math import *".

Here is the code:

Code:
EXPORT VTEST()
BEGIN
PYTHON(vt);
END;

#PYTHON EXPORT vt()
#start
from math import *

# set up equations
y0=lambda x:x+1
y1=lambda x:x**2+1
y2=lambda x:log(x)

# in this mode all has to be typed
def ftab(a,b,n):
  h=(b-a)/n
  print("\nx \ty0 \ty1 \ty2")
  for i in range(n):
    f0=y0(a)
    f1=y1(a)
    f2=y2(a)
    print('%.4f\t%.4f\t%.4f\t%.4f'% (a,f0,f1,f2))
    a+=h

# inputs
a=float(input("low? "))
print(a)
b=float(input("\nhigh? "))
print(b)
s=int(input("\nsteps? "))
print(s)

ftab(a,b,s) 
  
#end

Observations:

1. Every time I changed the code, the HP rebooted. Fortunately the changes are retained.

2. Everything has to be typed out, and in the correct case. There are no command menus to help with the syntax. I guess we can use a blank Python app and then copy the code into a PPL program after testing?

3. Another print statement is required to show the user just entered after an input on the terminal. I find it quite annoying.

4. \t shows a box.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Some Python Scripts to understand Variables Transfer - Eddie W. Shore - 10-26-2022 02:04 AM



User(s) browsing this thread: 1 Guest(s)