Startup:



Startup:

from visual import *

Vectors:

a=vector(1,2,3)

a.x, a.y, a.z

mag(a)

# this line is a comment

Variables:

a = 3 # an integer

b = -2. # a floating-point number

c = vector(0.4, 3e3, -1e1) # a vector

Earth = sphere(pos=(0,0,0), radius=6.4e6) # a Visual object

bodies = [ship, Earth, Moon] # a list of objects

Operations:

2/3 (returns 0)

2./3.(returns 0.666666)

5**2 (powers)

from __future__ import division

- returns integers as floating point

- use two underscores before and after future

Printing/Input

x=raw_input('Enter x: ')

print "The speed is", v, "m/s."

Strings:

x=4.0

s=str(x)

Logical testing:

if x==y:

blah blah

elif x>y:

blah blah

else:

blah

Functions:

def function_name(arg1, arg2):

# statements

return something

Loops:

for i in arange(5): #short for arrayrange

ints = arange(10) #produces a sequence 0 to 10

for I in range(0,1,10)

statements

while 1: # infinite loop

rate(100)

statements

while x ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download