user input and error handling way of providing input and modifying program behavior we will make our python programs do the sameand write programs that can be run as terminal terminalpython myprog py arg arg arg where arg arg arg and so forth are input arguments to the program we again consider the air pressure calculation program abovebut now we want the altitude to be specified as command line argument rather than obtained by stopping and asking for input for instancewe want to run the program as followssterminal terminalpython altitude_cml py to use command line arguments in python programwe need to import module named sys more specificallythe command line argumentsorin realityany words we type after the command python altitude pyare automatically stored in list named sys argv (short for argument valuesand can be accessed from thereimport sys from math import exp sys argv[ float(hp #sea level pressure (kpa#scale height (mp exp(- / print(pherewe see that we pull out the element with index one from the sys argv listand convert it to float just as the input provided with the input function abovethe command line arguments are always strings and need to be converted to floats or integers before they are used in computations the sys argv variable is simply list that is created automatically when your python program is run the first elementsys argv[ is the name of the py-file containing the program the remainder of the list is made up of whatever words we type after the program filename words separated by space become separate elements in the list nice way to gain feel for the use of sys argv is to test simple program that will just print out the contents of the listfor instanceby writing this simple code into the file print_cml pyimport sys print(sys argv