Presentation is loading. Please wait.

Presentation is loading. Please wait.

공학컴퓨터프로그래밍 Python 1 2017. 04. 12 염익준 교수.

Similar presentations


Presentation on theme: "공학컴퓨터프로그래밍 Python 1 2017. 04. 12 염익준 교수."— Presentation transcript:

1 공학컴퓨터프로그래밍 Python 1 염익준 교수

2 Data types in python ‘데이터 타입’은 프로그래밍 언어에서 여러 종류의 데이터를 식별하는 분류하는 방식을 결정한다. 자료의 한 속성으로써 어떤 종류의 자료를 다루고 있는지 알려주고, 그 자료에 어떤 연산을 할 수 있는지를 제한한다. 파이썬은 타입에 대한 선언이 없는 동적 타이핑(dynamic typing) 언어임

3 Data types in python • 수치형 (Numeric types)
int : 정수형 객체로 일반적으로 10진수로 사용된다. -23, 10, 57 float:  부동소숫점 표현으로 8바이트에 정보를 저장하며 영문 E 다음에 지수부를 기술한다. 2.3e-06 complex: 복소수 표현을 지원하며 끝에 J를 붙인다. 3+5j

4 Data types in python • 순서형 (Sequence) String : 문자를 나열한 것 ABCDEGHI
List : 순서가 있는 값들의 나열 [1, 2, 5, ‘a’, ‘b’] tuple : list와 유사하나 삭제,수정 등 변경 불가능 (2, 4, 1)

5 실습 1

6 Bulit-in Function Function Built-in Function Library
특정 기능을 제공하기 위한 코드들의 집단 Built-in Function 언어에서 기본적으로 제공하는 함수. print(), input(), … abs(x) : 절대값 round(X, Y) : 반올림 (X를 반올림하여 Y자리까지) Library Built-in function들을 모아놓은 파일 특정 Library의 function을 호출하기 위해선 import libraryName 필요 math.ceil(x) : 올림 (“import math” is required) math.floor(x) : 버림 (“import math” is required)

7 실습 2

8 Type Casting Function Type casting is a way to convert a variable from one data type to another data type. Use TypeName(variable or value) ex) a = # a is float b = int(a) # b is int (type casting from float to int) c = str(a) # c is string (type casting from float to string)

9 Use type casting When we use input(), a = input(); # a is string
a = int(input()); # a is int

10 실습 3

11 과제 a b h s 위의 직각 삼각형의 두 변의 길이 a, b (string type)를 입력 받아 높이(h), 넓이(s)를 출력하는 프로그램을 만드시오. int(input()) or float(input()) or eval() 사용 금지 제곱근은 math library의 sqrt(x) 함수를 사용하여 구하시오. ex) sqrt(4) returns 2

12 출력 화면

13 과제 제출 방법 • 과제 파일 압축(zip) 후 아이캠퍼스 업로드 파일 이름 : _홍길동


Download ppt "공학컴퓨터프로그래밍 Python 1 2017. 04. 12 염익준 교수."

Similar presentations


Ads by Google