The following is the 1st program of VPython, introducing the programming language. I know you can hardly read the code, to have a better viewing experience, please choose Full Screen at the upper left hand corner.
VPython, is a programming language based on and developed from Python, this is to show the 3D object simulation by inserting Python. It has tremendous impact to computational Physics as we can visualise what is happening in the reality by putting a variety of parameters to the model in the simulation. In this episode, we will learn the basics of VPython, we will use the Trinket that provide very suer-friendly interface to view the code at the left hand side while running the code at the other side.
We use the function print("") to print the code we want to show at the dialogue box, with the "" to indicate it is a string, while without "" the program will interpret you are inputting value, such as integer, floating point, etc. Let's try to type the following codes.
print("(5.0-3.0)/(5.0+3.0)=")Also, It can print some commonly used symbol, like Pi, so we just type the following and then get the value. Let's approximate the value of Pi.
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))
print(1+1/1+1/(1*2)+1/(1*2*3)+1/(1*2*3*4)+1/(1*2*3*4*5)+1/(1*2*3*4*5*6))
Do you know how I get this approximation? Google Search or Wikipedia! How many digit of approximation of Pi can you get?
I print following code, just to let you know, it's done!
print("End of program.")