<개인공부> - IT/[Python]
Python Dictionary 자료형 사용해보기
Aggies '19
2018. 8. 20. 12:25
반응형
# 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
반응형