파이썬 공부 - 기본 문법 완료~

기본문법 까지 했다 ~ 강의 보면서 해보았던것들~

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
print("---------If-else------------")
# if-else
myage=19
if(myage>=40):
print ("아 한숨..")
elif (myage >=20):
print ("성인입니다")
else:
print("미성년입니다")

print("---------Function------------")
# Function
def greet(name):
print(f'안녕 {name}아, 잘 지내냐?')
print(f'안녕')
greet("영희")

def greet2(name, age, location):
print(f'{name} 는 {age} 이고 {location} 사는구나')

greet2('원형', '43', '분당')
greet2(age=43, name='원형', location='분당')

print("---------Loop------------")
# Loop
x=0
y=0
while x <4:
print("hello world in while", x,y);
print(y)
y=y+1
x=x+1

for a in range(3):
print("hello world in range",a)

print("---------List------------")
# List
x = []
x = list()
x= [1,2,3]
print(x)

x= [[1,2],[3,4]]
print(x)

x.append(4)
x.append(5)
print(x)

y=x.pop()
print(x)
print(y)

x[1]= 999
print(x)

x=["철수", "민수", "토마스", "민혜", "민수2"]
print(x)

print("---------Tuple------------")
# Tuple // immutable
x = (1,2,3)
print(x)
#x[0] = 1 # error

print("---------Set------------")
# Set (세트) // immutable, 검색 속도가 빠르다
x = set()
x.add(1)
x.add(2)
print(x)

x= {1,2}
print(x)

x= set(("1","2","3"))
# x[0]=1 # error
print(x)

x = set(("민수", "철수", "영희"))
print(x)

x = [1,2,3,4,5,6]
print(7 in x)

print("---------Dictionary------------")
# Dictionary 사전, hash table
# Key와 Value, Key 의 빠른 검색
x = {}
x = dict()
print(x)

x["이름"] ="미로"
x["나이"] =20

print(x)
print(x["이름"])

print ("이름" in x)
print ("미로" in x)
print ("성별" in x)

x = { 1,2,3}
print (1 in x)

# Summary

# list vs tuple
# list: mutable vs immutable
# 1) list + tuple: ordered 순서가 정해져있다 - 내용물이 자료구조에 들어간 순서대루
# 2) 멤버쉽 검색이 느리다

# set vs dictionary
# set: key value 가 필요 없고 key 만 필요 할때
# dict: key, value가 필요 할때
# 1) set + dictionary: unordered
# 2) 검색이 빠르다

# Class and Heritance
print("---------Class------------")
class Person:
def __init__(self,name):
self.name=name
def say_hello(self):
print("안녕 나는 " + self.name)

a=Person("Mike")
b=Person("Miro")

a.say_hello()
b.say_hello()

print("------------Module, Package-----------")
# Module(file), Package(folder)
# import <PackageName><ModuleName>
import msg.email # Module name = File name
import msg.sms # from package import module
from msg import sms

e= msg.email.Email()
s= msg.sms.SMS()

e.send("mike", "miro", "hi")
s.send("miro", "mike", "hi2")
s.ping("010-123-1234")

print("------------Package call/ Geopy-----------")
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="app")
location = geolocator.geocode("Seoul, Korea")
print(location.address)
print((location.latitude, location.longitude))
print(location.raw)
#Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, ...
#print((location.latitude, location.longitude))
#(40.7410861, -73.9896297241625)
#print(location.raw)
#{'place_id': '9167009604', 'type': 'attraction', ...}

패스트캠퍼스 테크보이 워니 강좌 수강

테크보이 워니의 파이썬 코딩 클래스 수강 했다

  1. 기본 문법
  2. 자동 매매 봇

기존 프로그래밍 언어보다 정말 편하네~

온라인 개발 환경도 이번에 많다는걸 알게 되었다.
강좌에선 replit을 사용 하는데 갑자기 입력 오류가 생겨 고쳐질때까지 다른 서비스를 찾아보니 구글 콜라보라고 있는데 여기서도 많이 하는구나.

찾아보면서 많은 무료 강좌들이 올라 와 있어 나중에 시간 될때 찬찬히 해보고 싶다.

구글 콜라보

토요일 자바 공부

빵형 책을 ch5까지 보고 진도 나간것을 활용해서 “1~3까지의 랜덤 숫자를 여러번 돌려보고 분포 확인” 코드를 짜보았다.

‘’’
Scanner sc = new Scanner(System.in);
System.out.println(“How many trial?”);
System.out.print(“>”);
int trial = sc.nextInt();

    for(int z = 0 ; z < 10; z++)
    {
        int num = 0;
        Random random = new Random();
        int[] cnt = { 0, 0, 0, 0 };
        
        for(int x = 0 ; x < trial ; x++ )
        {
            num = random.nextInt(3)+1;
        //    System.out.printf("%dth 난수: %d\n", x+1, num);
            cnt[num]++;
        }
        
        System.out.println("=======================================");        
        System.out.println(trial + " many trial > randome gen");
        System.out.println("=======================================");
        for(int x = 1; x < 4; x++)
        {
            System.out.println("[" + x +"]" + " ->" + ((float)cnt[x]/trial) *100+" % many");
        }
    }
    System.out.println("================END====================");
}

100 many trial > randome gen

[1] ->39.0 % many
[2] ->33.0 % many
[3] ->28.0 % many

1000 many trial > randome gen

[1] ->34.2 % many
[2] ->32.7 % many
[3] ->33.1 % many

100000 many trial > randome gen

[1] ->33.293 % many
[2] ->33.335 % many
[3] ->33.372 % many
‘’’

100번, 1,000번, 100,000번 돌려보니 많이 돌리면 돌릴수록 33.33% 으로 수렴되는 것을 볼수 있다.

GitHub Page/Jekyll 조합 - 2. 왜 반영이 안되는거야?

Github pages 호스팅용 repo 만들고 Jekyll 설치를 했다.

짧게 읽고 보고 해보는데 고친 내용이 계속 반영이 안되는것이다.
알고 보니 내가 수정 한 내용에 에러가 있으면 이전 버전이 계속 나오더라.

즉 Git Hub에서 수정 해서 반영 하면 (Commit이라고 하는건가?) 그때 마다 빌드가 되고 과정에 에러가 있으면 Deployment, 반영이 안된다.

에러 아이콘이 있었는데 그걸 안 눌렀으면 포기 했을뻔했네!..

그렇군…

GitHub Page/Jekyll 조합 - 1. 첫 시도

IT 국비를 하면서 개발 블로그와 포토폴리오 올리는게 필요 하다고 생각되었다.
이리저리 검색을 해보고 깃헙에서 해보기로 했다.

테티노트의 깃헙 블로그 10분안에 완성하기 를 참조 했는데 나는 10분 더 걸렸다.

깃헙이 첨인지라 상당히 오래 걸렸고 Jekyll 설정 찾는것도 보기 힘들고 난잡하다.
억지로 억지로 페이지를 올렸다.

완성도 있게 하려면 아래 영상을 봐야 하는데 일단 내용도 많고 오픈소스, 클라우드 툴이기에 조금만 시간이 지나도 영상의 내용대로 따라하기가 안되는 문제가 있다.

요약:

  1. 개발 블로그, 포토폴리오 만들기로 결정
  2. Github pages 호스팅용, Jekyll 설치
  3. 생산성 극악 인 상태에서 좀 해보기로..