CS 지식/[codeit] 컴퓨터개론 (완)

[ codeit ] 컴퓨터개론 - 프로그래밍 시작하기 in Python

web_seul 2021. 5. 4. 19:16
반응형

 파이썬 첫 걸음 

 1강. 우리가 사용할 도구들 

Phython interpreter : 파이썬코드를 컴퓨터 언어로 번역하는 프로그램

PyCharm : 올인원 솔루션 ( IDE )

 

 2강. 파이썬 설치 (Window) 

Phython 검색 - 다운로드

PyCharm 검색 - 다운로드

프로그램 설치 후 프로젝트 저장공간 생성, 실행

 .py : 파이썬파일

print("Hello world!")

 

 3강. 파이썬 설치 (Mac) 

pass-

 

 4강. PyCharm 둘러보기 

new - file (or python) 생성

▶ run : 파이썬 실행 ( 최신에 실행한 파일이 실행됨 ) = ctrl + R(또는 f5)

print(2*5)
#10

 

+) 실습과제

12를 출력하세요

 

 프로그래밍 기본 개념 

 1강. 코멘트

# : 코멘트 (=주석)

복잡한 코드 설명 / 하다가 만 부분 표시 / 다른 개발자들과 소통

#코멘트
print("Hello World"); #여기도 주석

 

 2강. 자료형 개요

컴퓨터 = 복잡한 계산기

프로그래밍이란? 계산할 수식들을 컴퓨터에게 알려주는 것

자료형(Data Type) 

- 숫자 : 정수(integer), 소수(floating point) 

  ex) -1, 2, 10 ... 3.14, 2.0

- 문자열(string) 

  ex) "Hello", "2"

숫자열 2 + 5 = 7 / 문자열 "2" + "5" = "25"

- 불린(boolean) : true, false

  ex) 7 > 3 ->true

 

 3강. 추상화 개요

추상화(Abstraction) : 복잡한 내용은 숨기고, 주요 기능에만 신경쓰자 ex) 변수, 함수, 객체

- 변수 (variable) : 값을 저장하는 것

x = 254
y = 317

print(x+y)

 

- 함수 (function) : 명령을 저장하는 것

  ex) print : () 내의 값이 출력되도록하는 함수

 

 4강. 변수

print(4990)
print(4990 *2)
print(4990 + 1490)
print(4990 *3 + 1490 *2 + 1250 *5)

문제점 : 매번 반복입력, 잘못입력 가능성, 명시성↓, 수정어려움

= : 지정연산자, 우항의 값을 좌항에 넣음

burger_price = 4990
fries_price = 1490
drink_price = 1250

print(burger_price)
print(burger_price *2)
print(burger_price + fries_price)
print(burger_price *3 + fries_price *2 + drink_price *5)

 

 5강. 칼로리 계산기

+) 실습과제

정해진 칼로리의 과자를 먹었을 때 변수 설정하기

 

 6강. 함수

#def : 새로운 함수를 정의하겠다 (= define)

def hello():
    print("Hello!")
    print("Welcome to Codeit!")
    
hello()

#Hello!
#Welcome to Codeit!

 

 7강. 카페모카 레시피

+) 실습과제

모카레시피 출력하기 cafe_mocha_recipe

def cafe_mocha_recipe():
    print("1. 준비된 컵에 초코 소스를 넣는다.")
    print("2. 에스프레소를 추출하고 잔에 부어 준다.")
    print("3. 초코 소스와 커피를 잘 섞어 준다.")
    print("4. 거품기로 우유 거품을 내고, 잔에 부어 준다.")
    print("5. 생크림을 얹어 준다.")
    
cafe_mocha_recipe()
cafe_mocha_recipe()

 

 8강. 파라미터

함수에 넘겨주는 값

#name = Chris
def hello(name):
    print("Hello!")
    print(name)
    print("Welcome to Codeit!")
    
hello("Chris")

#Hello! 
#Chris 
#Welcome to Codeit!


#name = Michael
def hello(name):
    print("Hello!")
    print(name)
    print("Welcome to Codeit!")
    
hello("Michael")

#Hello! 
#Michael 
#Welcome to Codeit!

파라미터인 name 에 Chris, Michael 등 필요에 따라 다른값 추출

 

 9강. 여러개의 파라미터

#2개의 파라미터
def print_sum(a, b):
    print(a + b)
    

print_sum(7,3)
#10


#3개의 파라미터
def print_sum(a, b, c):
    print(a + b + c)
    

print_sum(7, 3, 2)
#12

 

 10강. 세 수의 곱

+) 실습과제

세 수의 곱을 출력하는 함수 multiply_three_numbers

def multiply_three_numbers(a,b,c):
    print(a*b*c);

 

 11강. return문

def get_square(x):
    return x*x
    
y = get_square(3)
print(y)
#9
def get_square(x):
    return x*x
    
print(get_square(3) + get_square(4))
#9 + 16
#25

 

* print와 return의 차이

print : 화면 출력o, 값 반환x

return : 값 반환

print(x*x) : none
return(x*x) : x2

 

 12강. 프로그래밍 기초 퀴즈

 

반응형