Q:

Why is my local variable said to be unassigned when it is conditionally assigned? 

def get_date(date):
month = date[4:7] 
if month == "01":
    month_string = "January"
elif month == "02":
    month_string = "February"
elif month == "03":
    month_string = "March"
elif month == "04":
    month_string = "April"
elif month == "05":
    month_string = "May"
elif month == "06":
    month_string = "June"
elif month == "07":
    month_string = "July"
elif month == "08":
    month_string = "August"
elif month == "09":
    month_string = "September"
elif month == "10":
    month_string = "October"
elif month == "11":
    month_string = "November"
elif month == "12":
    month_string = "December"
return month_string

The variable 'date' is an input string in the form yyyy/mm/dd.  
This function tests to see if the month from the input yyyy/mm/dd is one of those numbers and assigns a string to that number value.  Shouldn't this decision structure assign a value to month_string?  I don't understand why it is not. 

A:

Make this:
def get_date(date):
    month = date[5:7]
    month_string = None
    ...

date[5:7] is the mm part, while date[4:7] is /mm
Also, month_string = None handles the case the month is not valid.