Ex_interm_python_conda

Exercise: intermediate Python

You will exercise the following concepts

  • sequences (lists)
  • loops
  • functions
  • exception handling

Problem: You are presented with aggregated census data containing the male and female population across different states. You need to calculate the sex ratio and print that out in the format:

Male:female ratio in AL is 1.22:0.82
Male:female ratio in AZ is 1.04:0.96

Complete the following code

In [ ]:
states_list = ['AL', 'AZ', 'AK', 'AR', 'CA', 'CO', 'CT']
males = [55, 51, 52.9, 'tuesday', [53], 49, 50]
females = [45, 49, 48.1, 48.5, 47, (51), 50]
In [ ]:
def sex_ratio_by_states(#write the parameters to accept states, population):
    
    for #write a for loop that iterates through each element in the list:
        s = states_list[i]
        m = males[i]
        f = females[i]
        
        # write exception handling logic for the code below
            male_ratio = round(m/f, 2)
            female_ratio = round(f/m, 2)

            print("Male:female ratio in {} is {}:{}".format(s, str(male_ratio),
                                                           str(female_ratio)))
        
            print("Error processing state: " + s)
            continue

Run the cell below when you are ready

In [ ]:
sex_ratio_by_states(states_list, males, females)

Install arcgis package in a new env using conda

  1. Create a new environment called arcgis_handson with Python 3.6
  2. activate that environment
  3. Install arcgis package from esri channel
  4. Install pandas package from default channel
  5. Install matplotlib package
  6. Install numpy package, was it already installed?