''' Purpose: naming allows abstraction Author: Jim Cohoon ID: jpc ''' # get access to Python math comutational resources import math # There are several libraries we can import so we can use # things defined in those libraries in our programs! # Variables, functions, and other stuff are in those libraries and # math library is one of them. # import!! import says "hey I wanna use another library so give # me access" and when we use it we do # libraryname.whateverwewannause (this is the format not what # you actually type) like math.pi # . operator is selecting from the library # demonstrate the two math constants print( 'Python approximation of pi:', math.pi ) print( 'Python approximation of Euler\'s number:', math.e ) # Why won't calculations be perfect in Python? They're approximations # up to 15 digits! *important* print() print() # show some math computation a = math.radians( 30 ) b = math.radians( 45 ) # Why did I do a = math.radians ( 30 )? To store whatever # the result of math.radians(30) is in a. # If I just called the function then it executes but I didn't # store it anywhere. # .radians() is an ex of a function from the math library. It takes in # a number in degrees and gives you the radians equivalent. sin_a = math.sin( a ) tan_b = math.tan( b ) # .sin() will give you the sin of whatever angle (radians) you pass into it. # .tan() will give you the tan of whatever angle (radians) you pass into it. print( 'sin( 30 degrees ):', sin_a ) print( 'tan( 45 degrees ):', tan_b )