본문 바로가기
반응형

python27

Python Dictionary 자료형 사용해보기 # 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 d.. 2018. 8. 20.
Number of Things Challenge 함수 만들기 # Make a function how_many that, given a list of a number# and a thing name, returns a grmmatically correct sentence# describing the number of things.## >>>> how_many([5, "trinket"])# There are 5 trinkets.# >>>> how_many([1, "king"])# There is 1 king. def how_many(the_list): # Add code here that returns the answer sentence = "" for i in range(len(the_list)): if(i == 0): sentence += str(the_list[.. 2018. 8. 20.
Commafy 함수 만들기 # Make a function commafy that, given a list of three or more things,# returns a list with commas.## >>>> commafy(["trinket", "learning", "fun"])# trinket, learning, and fun# >>>> commafy(["lions", "tigers", "bears"])# lions, tigers, and bears def commafy(list): # Add code here that returns the answer objectCount = len(list) tempList = "" for i in range(objectCount - 1): tempList += list[i] + ",.. 2018. 8. 20.
Gerund 판단 함수만들기 # Make a function gerund_infinitive that, given a string ending in "ing", # returns the rest of the string prefixed with "to ". If the string# doesn't end in "ing", return "That's not a gerund!"## >>>> gerund_infinitive("building")# to build# >>>> gerund_infinitive("build")# That's not a gerund! def gerund_infinitive(string): # Add code here that returns the answer stringLength = len(string) isG.. 2018. 8. 20.
반응형