# Python 2.7 file for Numerical Methods II, Spring 2016 # http://www.math.nyu.edu/faculty/goodman/teaching/NumericalMethodsII2016/index.html # File: PythonBasics.py # See that you can run basic Python # Type: python PythonBasics.py ... and hope for the best print "Hello world, from python" # bullet 1 WelcomeString = "Hello world, again, from python" # bullet 2 print WelcomeString WelcomeStart = "A final hello world " # bullet 3 WelcomeEnd = "from python" print WelcomeStart + WelcomeEnd x = 10 # bullet 4 y = 3 print str(x) + " + " + str(y) + " = " + str(x+y) # bullet 5 print str(x) + " / " + str(y) + " = " + str(x/y) # bullet 6 x = 10.0 # bullet 7 OutputString = str(x) + " / " + str(y) + " = " + str(x/y) # bullet 8 print OutputString print "x has type " + str(type(x)) + ", and y has type " + str(type(y)) # bullet 9 DumbList = [] # bullet 10 print "DumbList has type " + str(type(DumbList)) DumbList.append(x) # bullet 11 DumbList.append(y) # bullet 12 DumbList.append(WelcomeString) print "Now DumbList has " + str( len(DumbList) ) + " items" # bullet 13 ListNumber = 0 # numbers the elements of DumbList for item in DumbList: # bullet 14 print "Item number " + str(ListNumber) + \ " has type: " + str(type(item)) + \ " and value: " + str(item) ListNumber = ListNumber + 1 print "DumbList has value: " + str(DumbList) # bullet 15 SmartList = DumbList # bullet 16 print "SmartList has value: " + str(SmartList) DumbList[0] = "Not ten" # bullet 17 print "Now DumbList has value: " + str(DumbList) # bullet 18 print "And SmartList has value: " + str(SmartList) # bullet 19 a = 5 b = a # This is a deep copy, why? a = 6 print "a = " + str(a) + ", and b = " + str(b) # bullet 20 m = 5 n = 10 iList = range(m,n) # bullet 21 print "iList has type " + str(type(iList)) + ", and value " + str(iList) squares = [] for i in range(m,n): # bullet 22 squares.append(i*i) print "The squares are: " + str(squares) # bullet 23