Language

반응형
반응형
Language/Python

[python]io_file_r,w,a,x

[io01_file 쓰기(만들기)] file = open('test01.txt', 'w') file.write('hello, world!') file.close() print('끝!') ''' r: 읽기 w: 쓰기(기존 내용 덮어쓰기) a: 쓰기(기존 내용 이후에 쓰기) x: 새로운 파일 만들어서 쓰기(이미 파일이 있으면 에러) t / b: text /binary(default: t) ''' [io02_file읽기] 위에서 만든 파일 안에 담긴 내용을 읽어준다. file = open('test01.txt', 'r') a = file.read() print(a) file.close() # 결과값 hello, world! [io03_file읽기_자동닫기] with을 사용하면 try-catch의 finally..

Language/Python

[python]math_원의 넓이

[module03] from math import pi import matplotlib.pyplot as plt def circle(x): #circle = x*x*pi circle =x**2*pi print('반지름이 {}인 원의 넓이는 {} 입니다.'.format(x, circle)) if __name__ == '__main__': r = input('원의 반지름: ') # 반지름이 r인 원의 넓이는 x 입니다. circle(int(r)) # 결과값 원의 반지름: 5 반지름이 5인 원의 넓이는 78.53981633974483 입니다.

Language/Python

[python]numpy, matplotlib_그래프

[module02] import random import numpy as np import matplotlib.pyplot as plt def plt01(): x = np.arange(0,11) y = x plt.plot(x,y) plt.xlabel('x') plt.ylabel('y') plt.legend(['y=x']) plt.show() def plt02(): # i가 아래에서 사용되지 않을때 _를 사용할 수 있음! y = [random.randint(0,10) for _ in range(10)] x = range(10) plt.bar(x,y) plt.xticks(range(11)) plt.yticks(range(11)) plt.show() def plt03(): data = [random.randi..

Language/Python

[python]random_랜덤, 로또

[ran01] # 모듈 또는 라이브러리 import random r1 = random.random() print(r1) # 0

Language/Python

[python]lambda_람다, 익명함수

[mtest04] # -*- coding: utf-8 -*- # lambda function : 익명함수 hap01 = lambda a, b: a + b print(hap01(10,20)) gob = lambda a, b: a * b print(gob(34,56)) hap02 = lambda a, b, c: a + b + c print(hap02(7,8,9)) a = [(1, 'one',9), (2, 'two',8), (3, 'three', 7), (4, 'four', 6)] # one two three four를 기준으로 정렬 a.sort(key=lambda a:a[1]) print(a) a.sort(key=lambda a:a[2]) print(a) min01 = (lambda x,y: x if xy ..

Language/Python

[python]함수02_구구단

[mtest03] # -*- coding: utf-8 -*- # 1. for문을 사용하여 구구단을 출력하는 gugu()라는 함수를 만들어 호출하자 # 2. while문을 사용하여 구구단 중 입력된 단을 출력하는 gugudan(x)를 만들어서 호출 # 단, x는 main에서 input() 함수를 사용하여 입력 def gugu(): for i in range(2,10): print('%d단'%i) for j in range(1,10): print('{}*{}={}'.format(i,j,i*j)) print() def gugudan(x): print(''%x) i = 0 while(i

emojiyeon
'Language' 카테고리의 글 목록 (11 Page)