''' Purpose: naming allows abstraction ''' # get access to Python math computational resources import math # helpful for special computations # input gives your program access to this library # Provides many things, including: # approximation of pi # approximation of e # demonstrate the two math constants print( 'Python approximation of pi:', math.pi ) print( 'Python approximation of Euler\'s number:', math.e ) print() print() # show some math computation a = math.radians( 30 ) b = math.radians( 45 ) # takes a degree value, returns the value in radians # decimal arithmetic is always an approximation! # "math" = identifier for the math library # . operator always takes part of something - selects a function from # the math library sin_a = math.sin( a ) tan_b = math.tan( b ) # the below line will round sin_a to 1 decimal point # sin_a = round( sin_a, 1 ) print( 'sin( 30 degrees ):', sin_a ) print( 'tan( 45 degrees ):', tan_b ) print() # show some helpful built-in math / math-like functions reply = input( 'Enter two numbers: ' ) n1, n2 = reply.split() n1, n2 = int( n1 ), int( n2 ) print( 'n1 =', n1 ) print( 'n2 =', n2 ) print() input( 'Enter when ready. ' ) # max and min are built-in functions # not part of the math library bigger = max( n1, n2 ) smaller = min( n1, n2 ) print( 'max( n1, n2 ):', bigger ) print( 'min( n1, n2 ):', smaller ) print() input( 'Enter when ready. ' ) # abs() finds the absolute value of a number # one use case would be distance pos_n1 = abs( n1 ) pos_n2 = abs( n2 ) print( 'abs( n1 ):', pos_n1 ) print( 'abs( n2 ):', pos_n2 ) print()