목록파이썬3 (66)
규도자 개발 블로그
[프로그래머스/Level1/파이썬3(python3)] 두 정수 사이의 합 문제 두 정수 a, b가 주어졌을 때 a와 b 사이에 속한 모든 정수의 합을 리턴하는 함수, solution을 완성하세요. 예를 들어 a = 3, b = 5인 경우, 3 + 4 + 5 = 12이므로 12를 리턴합니다. 제한사항 a와 b가 같은 경우는 둘 중 아무 수나 리턴하세요. a와 b는 -10,000,000 이상 10,000,000 이하인 정수입니다. a와 b의 대소관계는 정해져있지 않습니다. 입출력 예 abreturn 35123335312 풀이 def solution(a, b): small = a if a b else b answer = sum(range(small, big+1))..
[프로그래머스/Level1/파이썬3(python3)] 나누어 떨어지는 숫자 배열 문제 array의 각 element 중 divisor로 나누어 떨어지는 값을 오름차순으로 정렬한 배열을 반환하는 함수, solution을 작성해주세요. divisor로 나누어 떨어지는 element가 하나도 없다면 배열에 -1을 담아 반환하세요. 제한사항 arr은 자연수를 담은 배열입니다. 정수 i, j에 대해 i ≠ j 이면 arr[i] ≠ arr[j] 입니다. divisor는 자연수입니다. array는 길이 1 이상인 배열입니다. 입출력 예 arrdivisorreturn [5, 9, 7, 10]5[5, 10][2, 36, 1, 3]1[1, 2, 3, 36][3,2,6]10[-1] 입출력 예 설명 입출력 예#1 arr의 원..
[프로그래머스/Level1/파이썬3(python3)] 크레인 인형뽑기 게임 (2019 카카오 개발자 겨울 인턴십) 문제 게임개발자인 "죠르디"는 크레인 인형뽑기 기계를 모바일 게임으로 만들려고 합니다.게임개발자인 죠르디는 크레인 인형뽑기 기계를 모바일 게임으로 만들려고 합니다. "죠르디"는 게임의 재미를 높이기 위해 화면 구성과 규칙을 다음과 같이 게임 로직에 반영하려고 합니다. 게임 화면은 "1 x 1" 크기의 칸들로 이루어진 "N x N" 크기의 정사각 격자이며 위쪽에는 크레인이 있고 오른쪽에는 바구니가 있습니다. (위 그림은 "5 x 5" 크기의 예시입니다). 각 격자 칸에는 다양한 인형이 들어 있으며 인형이 없는 칸은 빈칸입니다. 모든 인형은 "1 x 1" 크기의 격자 한 칸을 차지하며 격자의 가..
[프로그래머스/연습문제/파이썬3(python3)] 가운데 글자 가져오기 문제 단어 s의 가운데 글자를 반환하는 함수, solution을 만들어 보세요. 단어의 길이가 짝수라면 가운데 두글자를 반환하면 됩니다. 제한사항 s는 길이가 1 이상, 100이하인 스트링입니다. 입출력 예 sreturn "abcde""c""qwer""we" 풀이 def solution(s): return s[(len(s)-1)//2: (len(s)//2) + 1] 설명 간단한 문자열 자르고 붙이기 문제이다. 원래 짝수의 경우와 홀수의 경우 둘로 나눠 if문으로 가르고 들어갔었는데 다른 사람의 훌륭한 풀이를 보고 개선하였다. 이렇게 멋진 해결책을 볼 때마다 시무룩하지 말고 수긍하고 배워나가는 자세를 유지해야하지 않을까 싶다.
파이썬3.x[python3.x]에서 요소가 하나인 튜플을 문자열이 아닌 튜플로 인식시키기 i_wanna_be_tuple = ('really') print(i_wanna_be_tuple) print(type(i_wanna_be_tuple)) u_need_to_do_like_this = ('like this',) print(u_need_to_do_like_this) print(type(u_need_to_do_like_this)) 어제 부딪힌 문제였다. django로 작업을 하던 와중 django form을 이용해 입력란을 만들고 있었는데 modelform은 상속받은 model을 기반으로 해서 입력 form을 작성해준다. 하필 입력받을 form 요소가 딱 하나였는데 이를 tuple형태로 정의해야하는 지라 단순..
[백준/1978/파이썬(python3)] 소수 찾기 문제 주어진 수 N개 중에서 소수가 몇 개인지 찾아서 출력하는 프로그램을 작성하시오. 입력 첫 줄에 수의 개수 N이 주어진다. N은 100이하이다. 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다. 출력 주어진 수들 중 소수의 개수를 출력한다. 입출력 예 입력출력 4 1 3 5 73 풀이 def prime_list(n): n = n + 1 #추가된 부분 sieve = [True] * n m = int(n ** 0.5) for i in range(2, m + 1): if sieve[i]: for j in range(i+i, n, i): sieve[j] = False return [i for i in range(2, n) if sieve[..
Objective Today we're working with Linked Lists. Check out the Tutorial tab for learning materials and an instructional video!A Node class is provided for you in the editor. A Node object has an integer data field, , and a Node instance pointer, , pointing to another node (i.e.: the next node in a list).A Node insert function is also declared in your editor. It has two parameters: a pointer, , p..
Objective Today we're discussing scope. Check out the Tutorial tab for learning materials and an instructional video!The absolute difference between two integers, and , is written as . The maximum absolute difference between two integers in a set of positive integers, , is the largest absolute difference between any two integers in .The Difference class is started for you in the editor. It has a..
Objective Today, we're taking what we learned yesterday about Inheritance and extending it to Abstract Classes. Because this is a very specific Object-Oriented concept, submissions are limited to the few languages that use this construct. Check out the Tutorialtab for learning materials and an instructional video!Task Given a Book class and a Solution class, write a MyBook class that does the fo..
Objective Today, we're delving into Inheritance. Check out the attached tutorial for learning materials and an instructional video!Task You are given two classes, Person and Student, where Person is the base class and Student is the derived class. Completed code for Person and a declaration for Student are provided for you in the editor. Observe that Student inherits all the properties of Person..