study with Q - 파이썬
-
37 - 백준 온라인 저지에서 여러 줄 입력 받기 - 추가문풀 필요study with Q - 파이썬 2024. 4. 22. 20:19
#여러 줄 입력 받기 위해서는 한 줄 입력 : input() 함수 하나 input() 두 줄 입력 : input() 함수 두 개 사용 input() input() 여러 줄 입력 : 반복문 사용 N = 10 for n in range(N): input() # 예시 문제 두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오. 입력 첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있으며, 각 줄에 A와 B가 주어진다. (0 > 5 1 1 >>> 2 2 3 >>> 5 3 4 >>> 7 9 8 >>> 17 5 2 >>> 7 백준 온라인 저지 > 12, 13 제외한 반복문 문제 풀기 replit 더보기 https://replit.com/@wh3308/onr..
-
36 - 수열의 일반항과 점화식, 등차 수열, 피보나치 수열 - 추가 문제 풀기study with Q - 파이썬 2024. 4. 16. 20:30
#등차수열 공차가 !2*이고 첫째 항이 !a_0*인 등차수열 !a_n*의 일반항을 구하면 !a_n = d(n-1)+a_0* 따라서 !a = [1,2,3,5,7,9,...]*인 수열에서 일반항은 !an = 2n-1* 즉, !n*에 대한 일차함수로 나타낼 수 있다. !n=100* 일 때 n = 100 a_n = 2*n -1 print(a_n) >>> 199 1부터 10까지의 항을 구하면 for n in range (1, 10+1): a_n = 2*n -1 print(a_n) >>> 1 3 5 7 9 11 13 15 17 19 ※ 주의! print가 for in 에 들어가 있어야 한다! 1번 째 ~ 10번 째 항이 들어가 있는 리스트를 구하면 a = [] for n in range (1, 10+1): a_n..
-
35 - 범위와 반복문study with Q - 파이썬 2024. 4. 15. 19:27
#범위 : 특정한 범위 내부의 정수들을 나열하는 자료형 : range()함수를 이용해서 만듦 : 매개변수에 숫자 1,2,3개를 넣어서 사용 매개변수에 숫자 1개를 넣는 방법 range(A) 0부터 A까지의 정수를 범위로 나열 A는 포함하지 않는다 매개변수에 숫자 2개를 넣는 방법 range(A, B) A부터 B까지의 정수를 범위로 나열 B는 포함하지 않는다 매개변수에 숫자 3개를 넣는 방법 range(A, B, C) A부터 B까지의 정수를 범위로 나열 B는 포함하지 않는다 C만큼 건너뛰면서 범위를 생성 예시) 매개변수에 숫자 1개 range(5) print(list(range(5))) >>> [0, 1, 2, 3, 4] 매개변수에 숫자 2개 print(list(range(10,20))) >>> [10, ..
-
-
33 - 딕셔너리 요소 변경 / 추가 / 제거study with Q - 파이썬 2024. 4. 10. 22:04
pro = { "제목" : "우아한 우주", "저자" : "엘라 프랜시스" } #요소의 값을 변경하는 방법 : 걍 다시 넣어주세요 #요소를 추가하는 방법 : 원하는 key와 값을 넣어준다 pro = { "제목" : "우아한 우주", "저자" : "엘라 프랜시스" } #요소 값 변경 pro["저자"] = "엘라 프랜시스 랜더스" #요소 추가 pro["옮긴이"] = "심채경" print(pro) >>> {'제목': '우아한 우주', '저자': '엘라 프랜시스 랜더스', '옮긴이': '심채경'} #요소를 제거하는 방법 :del 키워드를 사용 pro = { "제목" : "우아한 우주", "저자" : "엘라 프랜시스 랜더스", "옮긴이" : "심채경", "가격" : 15800 } del pro["가격"] prin..
-
32- 딕셔너리와 반복문study with Q - 파이썬 2024. 4. 9. 19:32
#어떤 제품을 관리한다고 할때, 리스트를 사용하면 pro = ["초콜릿이 통째로 칙촉", 500, "롯데제과", "과자", "2025.11.13" ] print (pro[3]) >>> 과자 ....그런데 이게 뭐드라 → 요소가 많아지게 되면 뭐가 어떤 값인지 헛갈림 #딕셔너리 ✓ 등장 배경 키: 값이 무엇인지 나타내는 것 값 : 값 이렇게 딕셔너리를 만들어서 product라는 변수에 넣게 되면 제품의 요소에 접근할 때, 대괄호[]를 사용하고 내부에 키를 입력해서 접근 가능. 그리고 나는 #키 : 값 뒤에 쉼표를 넣지 않아서 error 하나 떴음. product = { #키: 값 "제품명": "초콜릿이 통째로 칙촉", "분류":"과자", "유효기간": "2025.11.23" } print(product["..
-
-
30 - 중첩 리스트와 전개 연산자study with Q - 파이썬 2024. 3. 31. 11:14
#n-차원 리스트 1차원 리스트 : [0, 1, 2] 와 같이 한 겹으로 감싸진 리스트 2차원 리스트 : [[0, 1, 2] [3, 4, 5]]와 같이 두 겹으로 감싸진 리스트 ... n차원 리스트 : n겹으로 감싸진 리스트 #그래서 a = [[0, 1, 2], [3, 4, 5], [6, 7]] for i in a: print(i) >>> [0, 1, 2] [3, 4, 5] [6, 7] for i in a: for j in i: print(j) >>> 0 1 2 3 4 5 6 7 순서에 따라 바뀌는거 주의 더보기 a = [[0, 1, 2], [3, 4, 5], [6, 7]] for i in a: print(i) for j in i: print(j) >>> [0, 1, 2] 0 1 2 [3, 4, 5] 3..