본문 바로가기

Python

(68)
[Python/level 0] 길이에 따른 연산 - 181879, prod() 문제 설명 정수가 담긴 리스트 num_list가 주어질 때, 리스트의 길이가 11 이상이면 리스트에 있는 모든 원소의 합을 10 이하이면 모든 원소의 곱을 return하도록 solution 함수를 완성해주세요. prod()The math.prod() method returns the product of the elements from the given iterable.요소의 곱을 반환합니다.math.prod(iterable,start)math에 있는 함수이기 때문에 사용 시 import math를 먼저 해 주어야 합니다.ParameterDescriptioniterableRequired. Specifies the elements of the iterable whose product is computed b..
[Python/level 0] 대문자와 소문자 - 120893, swapcase() 문제 설명문자열 my_string이 매개변수로 주어질 때, 대문자는 소문자로 소문자는 대문자로 변환한 문자열을 return하도록 solution 함수를 완성해주세요. swapcase()The swapcase() method returns a string where all the upper case letters are lower case and vice versa.대문자 ↔ 소문자string.swapcase()참고자료: W3schools - Python String swapcase() Method Code - 1차def solution(my_string): answer = '' for i in my_string: if i.isupper(): answer += i..
[Python/level 0] 특정한 문자를 대문자로 바꾸기 - 181873, replace() 문제 설명영소문자로 이루어진 문자열 my_string과 영소문자 1글자로 이루어진 문자열 alp가 매개변수로 주어질 때, my_string에서 alp에 해당하는 모든 글자를 대문자로 바꾼 문자열을 return 하는 solution 함수를 작성해 주세요. code - 1차def solution(my_string, alp): answer = '' for i in my_string: if i == alp: answer += i.upper() else: answer += i return answerfor문 → if문my_string을 한 글자씩 i로 for문을 돌립니다.i가 alp와 동일하다면 즉, 대문자로 변경할 대상이라면 i.u..
[Python/level 0] 문자 반복 출력하기 - 120825, join() 문제 설명문자열 my_string과 정수 n이 매개변수로 주어질 때, my_string에 들어있는 각 문자를 n만큼 반복한 문자열을 return 하도록 solution 함수를 완성해보세요. join()The join() method takes all items in an iterable and joins them into one string.반복 가능한 문자열을 가져와 하나의 문자열로 결합합니다.A string must be specified as the separator.구분자를 지정해야 합니다.string.join(iterable)ParameterDescriptioniterableRequired. Any iterable object where all the returned values are stri..
[Python/level 0] 특정 문자 제거하기 - 120826, replace() 문제 설명문자열 my_string과 문자 letter이 매개변수로 주어집니다. my_string에서 letter를 제거한 문자열을 return하도록 solution 함수를 완성해주세요. replace()The replace() method replaces a specified phrase with another specified phrase.지정된 구문을 다른 구문으로 대체합니다.string.replace(oldvalue, newvalue, count)ParameterDescriptionoldvalueRequired. The string to search fornewvalueRequired. The string to replace the old value withcountOptional. A number..
[Python/level 0] 최댓값 만들기 (1) - 120847, sort(), sort(reverse=True) 문제 설명정수 배열 numbers가 매개변수로 주어집니다. numbers의 원소 중 두 개를 곱해 만들 수 있는 최댓값을 return하도록 solution 함수를 완성해주세요. code - 1차def solution(numbers): firstMaxNumber = max(numbers) indexMaxNumber = numbers.index(firstMaxNumber) numbers.pop(indexMaxNumber) secondMaxNumber = max(numbers) return(firstMaxNumber * secondMaxNumber)max(), index() → popfirstMaxNumber: max 함수를 이용해 numbers에서 가장 큰 값을 찾습니다.index..
[Python/level 1] 자연수 뒤집어 배열로 만들기 - 12932, reversed() 문제 설명자연수 n을 뒤집어 각 자리 숫자를 원소로 가지는 배열 형태로 리턴해주세요. 예를들어 n이 12345이면 [5,4,3,2,1]을 리턴합니다. reversed()reversed(sequence)The reversed() function returns a reversed iterator object.역순으로 순회할 수 있도록 iterator를 결과값으로 반환한다.ParameterDescriptionsequenceRequired. Any iterable object 참고자료: W3Schools - Python reversed() Function code - 1차def solution(n): listN = [] for i in str(n): listN.append(int(i)) ..
[Python/level 1] 자릿수 더하기 - 12931, map, sum 문제 설명자연수 N이 주어지면, N의 각 자릿수의 합을 구해서 return 하는 solution 함수를 만들어 주세요.예를들어 N = 123이면 1 + 2 + 3 = 6을 return 하면 됩니다. mapmap(function, iterables)ParameterDescriptionfunctionRequired. The function to execute for each item항목별로 실행할 기능iterableRequired. A sequence, collection or an iterator object. You can send as many iterables as you like, just make sure the function has one parameter for each iterable.반복..

반응형