본문 바로가기

파이썬127

223p.<실전 문제> : 바닥 공사 # 바닥 공사 n = int(input()) if n > 2: nlist = [0 for _ in range(n+1)] nlist[1] = 1 nlist[2] = 3 for i in range(3, n+1): nlist[i] = nlist[i-1]+nlist[i-2]*2 print(nlist[n] % 796796) else: print(n % 796796) 2022. 7. 14.
220p.<실전문제> : 개미 전사 # 개미 전사 n = int(input()) foods = list(map(int, input().split())) result1 = 0 result2 = 0 a = 0 def delmax(x): a = x.index(max(x)) print(x) if len(x) > 1: if max(x) == x[-1]: x.remove(x[-1]) x.remove(x[a-1]) elif max(x) == x[0]: x.remove(x[a]) x.remove(x[a]) else: x.remove(x[a]) x.remove(x[a]) x.remove(x[a-1]) nn = n / 2 nn = int(nn) for i in range(nn): result1 += max(foods) delmax(foods) if n % .. 2022. 7. 13.
217p.<실전문제> : 1로 만들기 # 1로 만들기 n = int(input()) numbers = [5, 3, 2] count = 0 while n > 1: for i in numbers: if n % i == 0: n /= i break elif (n-1) % i == 0: n -= 1 count += 1 n /= i break count += 1 print(count) 2022. 7. 11.
2-5. sqlite3 sqlite3 모듈은 무엇인가? 이를 설명하기에 앞서 우리는 sqlite를 짚고 넘어갈 수 밖에 없다. 왜냐하면 sqlite3는 sqlite라는 데이터베이스를 다루기 위해 파이썬에서 사용하는 모듈이기 때문이다. sqlite는 관계형 데이터베이스이다. 그렇다면 관계형 데이터베이스란 또 무엇인가? 행과 열로 이루어진 각각의 테이블에서 고유 값을 참조하여, 데이터를 단순히 관계나 표현식으로 나타내는 데이터베이스를 관계형 데이터베이스라고 하는 것이다. 다시 본론으로 돌아와 sqlite가 하는 일은 관계형 데이터베이스를 프로그래밍 쪽으로 제어하기 위해 sql을 실행하면 sqlite가 파일의 변화를 기록하는 것이다. sqlite3를 이용해 한번 데이터베이스를 구축해보겠다. 먼저 새 터미널을 열어 python을 입력.. 2022. 7. 10.