Language/Python

반응형
반응형
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

Language/Python

[python]함수01

[mtest01] # -*- coding: utf-8 -*- def func01(): print('함수 1 입니다.') def func02(): return '함수 2 입니다.' def func03(): return {1: 'first', 2: 'second'} # 프로그램의 주 진입점 : __가 붙어있으면 내부에서 사용하는 함수구나! if __name__=='__main__': func01() print(func02()) print(func03().get(1)) print(func03()[2]) # 결과값 함수 1 입니다. 함수 2 입니다. first second [mtest02] # -*- coding: utf-8 -*- def func01(x,y): return x + y def func02(x,y..

emojiyeon
'Language/Python' 카테고리의 글 목록 (8 Page)