import numpy as np # import the numpy module so we can do some real math, such as taking sine(x), this type of import allows us to call numpy ‘np’ try: # one of the many elegant python features is the TRY block, which doesn’t crash the program if the program makes an error! savefilename = "sinedata.txt" # make a string variable outfile = open(savefilename,'w') # use a built-in function to open a file for writing (create if necessary) for x in np.linspace(0,7,100): # ‘for loops’ cycle over a list, in this case a list of numbers generated by the numpy ‘linspace’ method, don’t forget the ‘:’ outfile.write(str(x) + " " + str(np.sin(x)) + "\n") # this string concatenation will be explained in class. Note ‘write’ is a method of the ‘file’ class. outfile.close() # it is always good to clean things up (close the file), and to print out a few messages to tell us that things worked print(savefilename + " created") except: print("Failure!")