반응형
# Make a function lookup_state that, given a US state abbreviation, returns the
# state's name.
#
# We've given you a dictionary with abbreviations as keys and state names as values.
# It's imported for you here:
from US import states
#
# Example:
# >>>> lookup_state("NC")
# North Carolina
def lookup_state(abbreviation):
return states.get(abbreviation)
# Add print statements to test what your function does:
print (lookup_state("NC"))
print (lookup_state("CA"))
print (lookup_state("NE"))
# Return None, not defined data
print (lookup_state("WD"))
print (lookup_state("MP"))
North Carolina California Nebraska None Northern Mariana Islands
반응형
'<개인공부> - IT > [Python]' 카테고리의 다른 글
Python Multiple return values (Tuple, Dict) (0) | 2018.08.23 |
---|---|
List 자료형의 Join함수 사용하기 (0) | 2018.08.21 |
Number of Things Challenge 함수 만들기 (0) | 2018.08.20 |
Commafy 함수 만들기 (0) | 2018.08.20 |
Gerund 판단 함수만들기 (0) | 2018.08.20 |