본문 바로가기
반응형

전체 글213

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.
Reverse String 함수 만들기 # Make a function reverse_string that, given a string, # returns that string in reverse## >>>> reverse_string("arg")# gra# >>>> reverse_string("Hi!")# !iH def reverse_string(string): # Add code here that returns the answer revString = "" # Reversed keyword : Making decremented for loop for i in reversed(range(len(string))): revString += string[i] return revString # Add print statements here to t.. 2018. 8. 20.
isupper(), islower() 함수이용하여 문자열의 대소문자 변경하기 def switchcase(string): switchcaseStr = "" for index in range(len(string)): # Condition : lowercase letter, replace lowercase letter to uppercase letter if (string[index].islower()): asciiIndex = ord(string[index]) - 32 switchcaseStr += chr(asciiIndex) # Condition : uppercase letter, replace uppercase letter to lowercase letter elif (string[index].isupper()): asciiIndex = ord(string[index]) + 32.. 2018. 8. 19.
반응형