본문 바로가기

python20

파이썬 알고리즘 강의/파이썬 기초 문법 3_조건문(if 분기문, 다중 if 문) 파이썬은 들여쓰기가 굉장히 중요하다 ''' 조건문 if(분기, 중첩) ''' x = 7 if x == 7: print("lucky") print("ㅋㅋ") ''' lucky ㅋㅋ ''' 🧶중첩 if 문 ''' 중첩 if 문 ''' x = 15 if x>=10: if x%2==1: print("10이상의 홀수") ''' =>result 10이상의 홀수 ''' 🧶and , or x=7 if x>0 and x=80: print('B') elif x>=70: print('C') elif x>=60: print('D') else: print("F") #2 x = 80 if x>=90: print('A') if x>=80: print('B') if x>=70: print('C') 2021. 9. 20.
파이썬 알고리즘 강의/파이썬 기초 문법 2_변수입력과 연산자 ''' 2.변수입력과 연산자 ''' ''' a = input("숫자를 입력하세요:") print(a) ''' a , b = input("숫자를 입력하세요:").split() # 2,3을 분리 print(a+b) => 위와 같은 경우 2 와 3이 문자열이기 때문에 더해도 수가 붙어서 나옴 a , b = input("숫자를 입력하세요:").split() # 2,3을 분리 a = int(a) print(type(a)) => int 형으로 변환 a , b = input("숫자를 입력하세요:").split() # 2,3을 분리 a = int(a) b = int(b) print(a+b) ''' input 2 3 =>5 ''' 🧶map을 사용하여 정수로 변환하기 split의 결과를 매번 int로 변환해주려니 귀찮습니.. 2021. 9. 20.
파이썬 알고리즘 강의/파이썬 기초 문법 1_변수와 출력함수 변수명 정하기 1. 영문과 숫자, _로만 이루어진다 2. 대소문자를 구분한다 3. 문자나, _로 시작한다 4. 특수문자를 사용하면 안된다 (&, %등) 5. 키워드를 사용하면 안된다(if , for ) ''' 1.변수와 출력함수 ''' a = 1 print(a) A = 2 print(a, A) A1 = 3 print(a, A, A1) # 2b=4 주석처 #한꺼번에 변수 선언 가능 a,b,c=3,2,1 print(a,b,c) #값 교환 a,b=10,20 print(a,b) a,b = b, a print(a,b) #변수 타입 a=12345 print(type(a))#int a=12.234567899999912345678 #8바이트만 나온 print(type(a))#float a='student' print(.. 2021. 9. 18.
Seaborn 시각화 연습_Heatmap,Pairplot,jointplot,tsplot Pinkwink님 블로그를 보고 연습하였다. https://pinkwink.kr/986?category=522424 pairplot 이랑 jointplot은 정말 유용하게 사용 할 수 있을거 같다. [Seaborn 연재] pairplot, jointplot, tsplot 익히기 Seaborn이 제공하는 그래프 중에 오늘은 pairplot, jointplot, tsplot에 대해 이야기를 할려고 합니다^^. 특히 pairplot이 주는 재미난 결과는 꽤 마음에 드실겁니다.^^ Seaborn [Seaborn 연재] set_style과 boxpl.. pinkwink.kr In [12]: import numpy as np import seaborn as sns from matplotlib import pyplo.. 2021. 5. 14.
83일차//python/ function/ 파이썬 ''' functoin func(,){ } ''' def func(): print('func()호출') func() ''' func()호출 ''' def funcRange(val, n): for i in range(n): print(val) funcRange("안녕", 3) ''' 안녕 안녕 안녕 ''' #가변인수(인자) func() def funcRange1(n, *values): for i in range(n): for v in values: print(v) print() funcRange1(3,"안녕","하이","파이썬") #default 인수 def funcRange2(value, n=3): for i in range(n): print(value) funcRange2("안녕하세요") #defaul.. 2021. 5. 6.
82일차//python/ 가위바위보 프로그램/ 파이썬 ''' 가위 바위 보하는 프로그램 계산기와 가위 바위 보를하는 프로그램을 작성해 보겠습니다. 가위 바위 보를 각각 0,1,2의 정수로 표현합니다. 당신은 입력으로 입력하게 합니다. 컴퓨터는 난수(동일한 확률로 마구 수를 자동으로 생성하는 방법)을 사용하여 생성합니다. 구체적으로는 random.randint(최소값, 최대 값) 수식을 사용하면 자동으로 최소값에서 최대 값까지 터무니없는 정수를 만들어줍니다. (프로그램의 시작에 'import random'의 선언이 필요) comp = random.randint(0,2) 이렇게하면이 comp 0 또는 1 또는 2의 정수가 할당됩니다. 입력한 당신의 숫자와 com을 비교하여 가위 바위 보 승부를 할 수있는 프로그램을 만드십시오. 가위 바위 보 당신은? (0 : .. 2021. 5. 4.
82일차//python/import math + random import math print(math.sin(1)) print(math.cos(1)) print(math.tan(1)) print(math.floor(2.5)) # 내림 print(math.ceil(2.5)) # 올림 # 사사오입 원칙. 반올림할 자리의 수가 5이면 반올림할 경우 앞자리가 짝수면 내림, 홀수면 올림 print(round(1.5)) print(round(2.5)) print(round(3.1415, 2)) print(round(31.415, -1)) import random print(random.random()) # 0.0 2021. 5. 4.
81일차//python/dictionary 1. Dictionary (dict) Dictionary는 "키(Key) - 값(Value)" 쌍을 요소로 갖는 컬렉션이다. Dictionary는 흔히 Map 이라고도 불리우는데, 키(Key)로 신속하게 값(Value)을 찾아내는 해시테이블(Hash Table) 구조를 갖는다. 파이썬에서 Dictionary는 "dict" 클래스로 구현되어 있다. Dictionary의 키(key)는 그 값을 변경할 수 없는 Immutable 타입이어야 하며, Dictionary 값(value)은 Immutable과 Mutable 모두 가능하다. 예를 들어, Dictionary의 키(key)로 문자열이나 Tuple은 사용될 수 있는 반면, 리스트는 키로 사용될 수 없다. Dictionary의 요소들은 Curly Brace .. 2021. 5. 3.
81일차//python/ list, tuple list, tuple #list ,tuple #사용법은 거의 동일 #list(추가, 삭제가능) tuple 은 (추가X, 삭제X) [a,b] = [10,20] #list (c,d) = (11,22) #tuple print(a) print(b) print(c) print(d) a = 100 print(a) c = 111 print(c) #tuple tuple_test = (10,20,30) print(tuple_test[0]) #tuple_test[0]= 100 에러 발생 mylist = list(tuple_test) #tuple을 list로 변경후에는 값을 변경 가능 mylist[0] = 100 print(mylist[0]) list 추가 삭제 #list - >array(동적) mylist = [23,56.. 2021. 5. 3.