The following is the 2nd program of VPython, demonstrating to assign symbol for calculation. I know you can hardly read the code, to have a better viewing experience, please choose Full Screen at the upper left hand corner.
Firstly, I want to try the calculation function in VPython, so I use the operator addition, subtraction, multiplication, division to find the answer:
print("(5.0-3.0)/(5.0+3.0)=")
print( (5.0-3.0)/(5.0+3.0))
print("(10.0-3.0)/(10.0+3.0)=")
print( (10.0-3.0)/(10.0+3.0))
Without doubt, it can give me accurate answer shortly. Then, I want to assign value and run operation to see it also works. That's what I want to calculate:
print("However, we can set variable, like a=10 and b=3.We can change the value from time to time.")
print("now a=10.0, b=3.0. c=(a-b)/(a+b), d=(a-b)/(a+b)")
So now I assign value to the parameter a and b, for c and d are the calculation part.
a=10.0
b=3.0
c=(a-b)/(a+b)
d=(a-b)/(a+b)
print("c=")
print( c)
print("d=")
print(d)
print("c^2=")
print(c**2)
Now, answers are given out at the right hand side!
The print the following code, just to let you know, it's done!
print("End of program.")
Feel free to edit the code to see what changes you can make to this simulation!