'찌봉'이라는 스터디 이름을 만들었다. 객체 지향 전까지는 같이 했다. 그리고 더이상 지인과 파이썬 스터디는 하지 않는다.

반응형
블로그 이미지

두리뭉실:해피파인더그룹

컴퓨터 코치 두리뭉실

,

변수

컴퓨터 언어에선 '변하는 수' 보다는 '하나의 데이터를 저장 할 수 있는 메모리 공간'이라고 생각 하자. 나중에는 변수를 '데이터가 저장되어 있는 레퍼런스를 담는 메모리 공간'으로 디테일 하게 이해 될 것이다.


1
>>> 철수의나이 = 17
cs
기본적인 변수 사용방법이다. '='를 기준으로 오른쪽의 있는 값왼쪽에 있는 변수에 저장 한다.


1
2
3
4
>>> 철수의나이 = 철수의나이 + 10
>>> 철수의나이
27
>>> 
cs

철수의나이 변수에 저장된 값과 10을 더해서 철수의나이 변수에 저장 한다. '=' 기준으로 어느쪽에 변수가 위치함에 따라 변수에 저장 할지 변수에 저장된 값을 가져 올지 결정 한다.


왜 변수를 사용할까 의문이 든다면, 앞으로 코드를 작성할때 변수를 사용안하고 작성해 보면 몸으로 느낄것이다.


질문

스터디를 하면서 연습문제에 대한 질문이 있었다. 

1) '반지름이 10 인 월의 넓이 = 314.1592' 이렇게 나와야 하는데 왜 '314.0'으로 나오나요? 원하는 만큼 소수부분을 출력하고 싶어요.

1
2
3
4
5
>>> 10 * 10 * 3.14
314.0
>>> 10 * 10 * 3.141592
314.1592
>>> 
cs

우리는 파이를 3.14로만 기억하지 3.141592를 기억하지 않는다. --.--;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


참고 코드

1
2
3
4
5
6
>>> import math
>>> math.pi
3.141592653589793
>>> 10 * 10 * math.pi
314.1592653589793
>>> 
cs


2) (num1 + num2 + num3) / 3으로 평균을 구했는데, 파이썬에서 제공하는 함수가 있나요?

있지만, 아직 초본이기 때문에 설명은 안하고 이렇게 평균을 구할 수 있는것만 알고 있자. 


1


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
>>> num1 = 30
>>> num2 = 90
>>> num3 = 120
>>> (num1 + num2 + num3) / 3
80.0
>>> import statistics
>>> dir(statistics)
['Decimal''Fraction''StatisticsError''__all__''__builtins__''__cached__''__doc__''__file__'
'__loader__''__name__''__package__''__spec__''_coerce''_convert''_counts''_exact_ratio'
'_fail_neg''_find_lteq''_find_rteq''_isfinite''_ss''_sum''bisect_left''bisect_right''collections'
'groupby''harmonic_mean''math''mean''median''median_grouped''median_high''median_low''mode'
'numbers''pstdev''pvariance''stdev''variance']
>>> help(statistics.mean)
Help on function mean in module statistics:
 
mean(data)
    Return the sample arithmetic mean of data.
    
    >>> mean([12344])
    2.8
    
    >>> from fractions import Fraction as F
    >>> mean([F(37), F(121), F(53), F(13)])
    Fraction(1321)
    
    >>> from decimal import Decimal as D
    >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")])
    Decimal('0.5625')
    
    If ``data`` is empty, StatisticsError will be raised.
 
>>> statistics.mean([num1, num2, num3])
80
>>> 
cs


마무리

변수가 무었인지 어떻게 사용하는지만 이해 했다면 좋다. 나머지는 경험을 통해서 배워가면 된다. 


다음글

이전글 2020/06/04 - [STUDY/파이썬] - [파이썬 스터디] 지인과 함께 하는 파이썬 with 두근두근 파이썬 No. 02 - IDLE와 turtle


반응형
블로그 이미지

두리뭉실:해피파인더그룹

컴퓨터 코치 두리뭉실

,

컴퓨터 프로그램

컴퓨터가 수행할 명령어를 적어 놓은 문서

어떤 문제를 해결하기 위해 컴퓨터에게 주어지는 처리 방법과 순서를 기술한 일련의 명령문 집합체

프로그래머

프로그램을 만드는 사람

IDLE

파이썬 코드를 작성하고 실행하고 저장하고 불러오는 것을 쉽게 해주는 것이 IDLE(Integrated Development and Learning Environment)다. 이 책의 코드를 작성하고 실행하는 것은 IDLE만으로도 충분할 것으로 생각 된다. 조금 인터넷을 검색해보면 '파이참' 또는 '주피터 노트북'이라는 통합개발환경 툴이 있다. 어느 것이든 한번쯤 사용해 보는걸 추천 하고, 툴 설치 사용에 서투르다면 나중에 해보길 바란다.

turtle

아마도 이 책을 혼자 공부를 한다면, 처음부터 막막할거 같다. 변수나 객체에 대한 얘기가 없기에 뭔지 모를거 같지만, 그냥 따라하면 된다. 어자피 앞으로 자세하게 배울테니까. 그리고 기존의 코드를 살짝 바꿔주고 결과가 어떻게 표시되는지 여러번 확인 하면, 정확하게는 아니더라도 대충은 어떻게 사용하는지는 알게 된다. 


1
2
3
4
5
6
7
>>> import turtle
>>> han = turtle.Turtle()
>>> han.shape('turtle')
>>> han.shape('turtle')
>>> han.forward(100)
>>> han.right(90)
>>> han.forward(100)
cs


이 코드를 하나씩 실행하게 되면 

화면이 하나 생기면서 

가운데 화살표가 표시 된다. 

그리고 화살표가 거북이로 변경 되고,

거북이가 보는 방향으로 100만큼 이동하면서 선이 그려진다.

그리고 시계방향으로 90도 거북이가 회전하고

거북이가 보는 방향으로 100만큼 이동하면서 선이 그려진다.


여러번 해본다면 어렵지 않게 자연스럽게  선을 그릴 수 있다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
>>> dir(turtle)
['Canvas''Pen''RawPen''RawTurtle''Screen''ScrolledCanvas''Shape''TK''TNavigator'
'TPen''Tbuffer''Terminator''Turtle''TurtleGraphicsError''TurtleScreen''TurtleScreenBase'
'Vec2D''_CFG''_LANGUAGE''_Root''_Screen''_TurtleImage''__all__''__builtins__''__cached__'
'__doc__''__file__''__forwardmethods''__func_body''__loader__''__methodDict''__methods'
'__name__''__package__''__spec__''__stringBody''_alias_list''_make_global_funcs'
'_screen_docrevise''_tg_classes''_tg_screen_functions''_tg_turtle_functions''_tg_utilities'
'_turtle_docrevise''_ver''addshape''back''backward''begin_fill''begin_poly''bgcolor''bgpic'
'bk''bye''circle''clear''clearscreen''clearstamp''clearstamps''clone''color''colormode'
'config_dict''deepcopy''degrees''delay''distance''done''dot''down''end_fill''end_poly'
'exitonclick''fd''fillcolor''filling''forward''get_poly''get_shapepoly''getcanvas'
'getmethparlist''getpen''getscreen''getshapes''getturtle''goto''heading''hideturtle''home'
'ht''inspect''isdown''isfile''isvisible''join''left''listen''lt''mainloop''math''mode'
'numinput''onclick''ondrag''onkey''onkeypress''onkeyrelease''onrelease''onscreenclick''ontimer'
'pd''pen''pencolor''pendown''pensize''penup''pos''position''pu''radians''read_docstrings'
'readconfig''register_shape''reset''resetscreen''resizemode''right''rt''screensize''seth'
'setheading''setpos''setposition''settiltangle''setundobuffer''setup''setworldcoordinates''setx'
'sety''shape''shapesize''shapetransform''shearfactor''showturtle''simpledialog''speed'
'split''st''stamp''sys''textinput''tilt''tiltangle''time''title''towards''tracer'
'turtles''turtlesize''types''undo''undobufferentries''up''update''width''window_height'
'window_width''write''write_docstringdict''xcor''ycor']
>>> dir(turtle.Turtle)
['DEFAULT_ANGLEOFFSET''DEFAULT_ANGLEORIENT''DEFAULT_MODE''START_ORIENTATION''__class__''__delattr__'
'__dict__''__dir__''__doc__''__eq__''__format__''__ge__''__getattribute__''__gt__''__hash__'
'__init__''__init_subclass__''__le__''__lt__''__module__''__ne__''__new__''__reduce__'
'__reduce_ex__''__repr__''__setattr__''__sizeof__''__str__''__subclasshook__''__weakref__'
'_cc''_clear''_clearstamp''_color''_colorstr''_delay''_drawturtle''_getshapepoly''_go'
'_goto''_newLine''_pen''_polytrafo''_reset''_rotate''_screen''_setDegreesPerAU''_setmode'
'_tracer''_undo''_undogoto''_update''_update_data''_write''back''backward''begin_fill''begin_poly'
'bk''circle''clear''clearstamp''clearstamps''clone''color''degrees''distance''dot''down'
'end_fill''end_poly''fd''fillcolor''filling''forward''get_poly''get_shapepoly''getpen''getscreen'
'getturtle''goto''heading''hideturtle''home''ht''isdown''isvisible''left''lt'
'onclick''ondrag''onrelease''pd''pen''pencolor''pendown''pensize''penup''pos''position'
'pu''radians''reset''resizemode''right''rt''screens''seth''setheading''setpos''setposition'
'settiltangle''setundobuffer''setx''sety''shape''shapesize''shapetransform''shearfactor''showturtle'
'speed''st''stamp''tilt''tiltangle''towards''turtlesize''undo''undobufferentries''up''width'
'write''xcor''ycor']
>>> help(turtle.Turtle.forward)
Help on function forward in module turtle:
 
forward(self, distance)
    Move the turtle forward by the specified distance.
    
    Aliases: forward | fd
    
    Argument:
    distance -- a number (integer or float)
    
    Move the turtle forward by the specified distance, in the direction
    the turtle is headed.
    
    Example (for a Turtle instance named turtle):
    >>> turtle.position()
    (0.000.00)
    >>> turtle.forward(25)
    >>> turtle.position()
    (25.00,0.00)
    >>> turtle.forward(-75)
    >>> turtle.position()
    (-50.00,0.00)
 
>>> help(han.forward)
Help on method forward in module turtle:
 
forward(distance) method of turtle.Turtle instance
    Move the turtle forward by the specified distance.
    
    Aliases: forward | fd
    
    Argument:
    distance -- a number (integer or float)
    
    Move the turtle forward by the specified distance, in the direction
    the turtle is headed.
    
    Example (for a Turtle instance named turtle):
    >>> turtle.position()
    (0.000.00)
    >>> turtle.forward(25)
    >>> turtle.position()
    (25.00,0.00)
    >>> turtle.forward(-75)
    >>> turtle.position()
    (-50.00,0.00)
 
>>> 
cs


help와 dir 내장함수를 이용하여 우리가 사용하는 것(?)에 대하여 정보를 얻을 수 있다.

반응형
블로그 이미지

두리뭉실:해피파인더그룹

컴퓨터 코치 두리뭉실

,

지인이 파이썬을 하고 싶다 하여, 지인의 일정에 마춰서 스터디를 만들었다. 아직 이름은 없다. 수요일 저녁 8시에 하기로 했으니까 그때 스터디 이름을 만들어야 겠다. 


생능출판사의 '두근두근 파이썬' 책으로 진행한다.

<두근두근 파이썬 표지>


학교 교재이기 때문에 강의 계획서도 있다.

•1주: 1장 파이썬 소개
•2주: 2장 변수
•3주: 3장 계산기능
•4주: 4장 자료의 종류
•5주: 5장 조건
•6주: 6장 반복
•7주: 7장 함수
•8주: 중간고사 중간 평가 및 프로젝트 제안서 발표
•9주: 8장 프로젝트 I
•10주: 9장 리스트와 딕셔너리
•11주: 10장 tkinter
•12주: 11장 파일
•13주: 12장 라이브러리 사용
•14주: 13장 객체와 클래스 개요
•15주: 14장 프로젝트 II
•16주: 기말고사 기말 평가 및 프로젝트 결과 발표


전반적인 내용을 다루지는 않지만, 입문서로는 괜찮은듯 하고 KAIT에서 진행하는 '파이썬 마스터' 자격증도 준비 할 수 있을거 같다. 부족한 부분은 문제 풀이를 통해 보충하면 되니까!


스터디 첫주 범위는 '1장 파이썬 소개' & '2장 변수'다. 내일 스터디를 위해서 연습문제를 풀면서 정리 해야 겠다.


다음글 2020/06/04 - [STUDY/파이썬] - [파이썬 스터디] 지인과 함께 하는 파이썬 with 두근두근 파이썬 No. 02 - IDLE와 turtle

이전글





반응형
블로그 이미지

두리뭉실:해피파인더그룹

컴퓨터 코치 두리뭉실

,