The purpose of this program is to retrieve, format, and print the shell environmental…
- User
The purpose of this program is to retrieve, format, and print the shell environmental variables for the user running the program. The program will:
only execute commands if execution occurred as a result of this program name being called and not when imported when imported, functions will only execute when called create a function called main that will call the other functions to perform the required actions create a function called retrieve_env_variables retrieve the environmental variables with associated values return the variable name with associated value create a function called format_env_variables formats the key/value pairs environmental variable name left justified within a 30 character string value formatting does not change create a function called print_env_variables prints the formatted environmental variable followed directly by a colon and a space followed directly by the value that the environmental variable holds end the line with one new line
- Assistant
Here is the proposed Python code:
python#!/usr/bin/env python3 import os def retrieve_env_variables(): variables = os.environ variable_list = [] for key, value in variables.items(): variable_list.append((key, value)) return variable_list def format_env_variables(variable_list): formatted_list = [] for variable in variable_list: formatted_list.append('{:<30}{}'.format(variable[0], variable[1])) return formatted_list def print_env_variables(formatted_list): for variable in formatted_list: print(variable + ":\n") def main(): variable_list = retrieve_env_variables() formatted_list = format_env_variables(variable_list) print_env_variables(formatted_list) if __name__ == '__main__': main()Note that this code only retrieves, formats, and prints the environmental variables. If you want to perform additional actions, you may need to modify the code accordingly.