import numpy as np def print_gamma( a, p, T ): ''' LAPSE RATE TABLE Print table of lapse rate as function of T and P To print table, provide: array of lapse rates (K/km) with m rows and n columns pressure values (mb, n columns) temperature values (deg C, m rows) ''' # ---------------------------------- # print table (do not change any code below) # print headers np.set_printoptions(formatter={'all':lambda x: '{0:<4}'.format(x)}) print(f"{'p (mb)':^30}") print('\t',p) print('T (C)') # print each row np.set_printoptions(precision=2) for i in range(T.shape[0]): print(T[i],'\t',a[i,:]) # --------------------------- # Calculate the lapse rate for different combinations # of temperature and pressure # --------------------------- # coordinates: pressure (mb), temperature (deg C) p_mb = np.array([1000,850,700,300,100]) # columns T_C = np.array([-40,-20,0,20,40,60]) # rows # make an m x n array of lapse rates (K/km) m = T_C.shape[0] # rows n = p_mb.shape[0] # columns gamma = np.zeros((m,n)) # assign some floating point numbers for i in range(m): for j in range(n): gamma[i,j] = 2*np.sqrt(i+j) # ---------------------------- # print a table of lapse rates # ---------------------------- print_gamma( gamma, p_mb, T_C)