''' Purpose: naming allows abstraction ''' # Never name variables max and min as you will never have access to the max and min functions after that! # max_price and min_age are valid names but max and min (and sum) are not valid names! Don't name variables those! # import math allows us to access the math library (functions and variables defined within the math library) # max() and min() are built in and are NOT part of the math library so there is no need to import to use max and min functions. # get access to Python math computational resources import math # 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 ) # .radians() is a function that returns the radians equivalent of an angle given in degrees. sin_a = math.sin( a ) tan_b = math.tan( b ) # .sin() is another function that takes in a value and gives us the sin value 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 ) # the int() function converts whatever is in the parantheses into an int. # So when we first get the values, reply.split() assigns n1 and n2 to the respective values of the list elements in order within the list created by # reply.split() so when we enter string '2 3' it will split it into list elements [ ' 2 ' , ' 3 ' ] and n1, n2 = reply.split() # will basically look like this: # n1, n2 = [ '2', '3' ] # and n1, n2 will get the string values respectively (n1 will get '2' and n2 will get '3') # we then assign those values to the integer conversions of those strings! print( 'n1 =', n1 ) print( 'n2 =', n2 ) print() input( 'Enter when ready. ' ) # These are the max and min functions which take in two numeric values and compute the max and min respectively. bigger = max( n1, n2 ) smaller = min( n1, n2 ) print( 'max( n1, n2 ):', bigger ) print( 'min( n1, n2 ):', smaller ) print() input( 'Enter when ready. ' ) # Lastly, this is the absolute value function which will simply return the absolute value of a number! pos_n1 = abs( n1 ) pos_n2 = abs( n2 ) print( 'abs( n1 ):', pos_n1 ) print( 'abs( n2 ):', pos_n2 ) print()