초보자를 위한 파이썬 300제 (251~260)
위키독스
온라인 책을 제작 공유하는 플랫폼 서비스
wikidocs.net
|
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
|
#251
'''
1. 클래스: 객체를 만들어 내기 위한 설계도 혹은 틀
2. 객체: 소프트웨어 세계에 구현할 대상
3. 인스턴스: 설계도를 바탕으로 소프트웨어 세계에 구현된 구체적인 실체
'''
#252
class Human:
pass
#253
class Human:
pass
areum = Human()
#254
class Human:
def __init__(self):
print("응애응애")
areum = Human()
#255
class Human:
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
areum = Human("아름", 25, "여자")
print(areum.name, areum.age, areum.sex)
#256
class Human:
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
areum = Human("아름", 25, "여자")
print(f"이름: {areum.name}, 나이: {areum.age}, 성별: {areum.sex}")
#257
class Human:
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
def who(self):
print(f"이름: {areum.name}, 나이: {areum.age}, 성별: {areum.sex}")
areum = Human("아름", 25, "여자")
areum.who()
#258
class Human:
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
def who(self):
print(f"이름: {areum.name}, 나이: {areum.age}, 성별: {areum.sex}")
def setInfo(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
areum = Human("불명", "미상", "모름")
areum.who()
areum.setInfo("아름", 25, "여자")
areum.who()
#259
class Human:
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
def __del__(self):
print("나의 죽음을 알리지마라")
def who(self):
print(f"이름: {areum.name}, 나이: {areum.age}, 성별: {areum.sex}")
def setInfo(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
areum = Human("아름", 25, "여자")
del(areum)
#260 오류내용: print()는 인자를 받지 않는데 1개가 들어갔다. 따라서 def print(a)라고 a 등 아무 문자열을 넣어주면 된다.
class OMG :
def print(a) :
print("Oh my god")
mystock = OMG()
mystock.print()
|
cs |
초보자를 위한 파이썬 300제 (261~270)
위키독스
온라인 책을 제작 공유하는 플랫폼 서비스
wikidocs.net
|
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
|
#261
class Stock:
pass
#262
class Stock:
def __init__(self, name, code):
self.name = name
self.code = code
삼성 = Stock("삼성전자", "005930")
print(삼성.name)
print(삼성.code)
#263
class Stock:
def __init__(self, name, code):
self.name = name
self.code = code
def set_name(self, name):
self.name = name
a = Stock(None, None)
a.set_name("삼성전자")
print(a.name)
#264
class Stock:
def __init__(self, name, code):
self.name = name
self.code = code
def set_name(self, name):
self.name = name
def set_code(self, code):
self.code = code
a = Stock(None, None)
a.set_code("005930")
print(a.code)
#265
class Stock:
def __init__(self, name, code):
self.name = name
self.code = code
def set_name(self, name):
self.name = name
def set_code(self, code):
self.code = code
def get_name(self):
return self.name
def get_code(self):
return self.code
삼성 = Stock("삼성전자", "005930")
print(삼성.name)
print(삼성.code)
print(삼성.get_name())
print(삼성.get_code())
#266
class Stock:
def __init__(self, name, code, per, pbr, 배당수익률):
self.name = name
self.code = code
self.per = per
self.pbr = pbr
self.배당수익률 = 배당수익률
def set_name(self, name):
self.name = name
def set_code(self, code):
self.code = code
def get_name(self):
return self.name
def get_code(self):
return self.code
#267
삼성 = Stock("삼성전자", "005930", 15.79, 1.33, 2.83)
print(삼성.배당수익률)
#268
class Stock:
def __init__(self, name, code, per, pbr, dividend):
self.name = name
self.code = code
self.per = per
self.pbr = pbr
self.dividend = dividend
def set_name(self, name):
self.name = name
def set_code(self, code):
self.code = code
def get_name(self):
return self.name
def get_code(self):
return self.code
def set_per(self, per):
self.per = per
def set_pbr(self, pbr):
self.pbr = pbr
def set_dividend(self, dividend):
self.dividend = dividend
#269
삼성 = Stock("삼성전자", "005930", 15.79, 1.33, 2.83)
삼성.set_per(12.75)
print(삼성.per)
#270
종목 = []
삼성 = Stock("삼성전자", "005930", 15.79, 1.33, 2.83)
현대차 = Stock("현대차", "005380", 8.70, 0.35, 4.27)
LG전자 = Stock("LG전자", "066570", 317.34, 0.69, 1.37)
종목.append(삼성)
종목.append(현대차)
종목.append(LG전자)
for i in 종목:
print(i.code, i.per)
|
cs |
초보자를 위한 파이썬 300제 (271~280)
위키독스
온라인 책을 제작 공유하는 플랫폼 서비스
wikidocs.net
|
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
#271
import random
class Account:
def __init__(self, name, balance):
self.name = name
self.balance = balance
self.bank = "SC은행"
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3) # padding(문자열 채우기)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
kim = Account("김민수", 100)
print(kim.name)
print(kim.balance)
print(kim.bank)
print(kim.account_number)
#272
import random
class Account:
account_count = 0
def __init__(self, name, balance):
self.name = name
self.balance = balance
self.bank = "SC은행"
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
Account.account_count += 1
kim = Account("김민수", 100)
print(Account.account_count)
lee = Account("이민수", 100)
print(Account.account_count)
#273
import random
class Account:
account_count = 0
def __init__(self, name, balance):
self.name = name
self.balance = balance
self.bank = "SC은행"
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
Account.account_count +=1
def get_account_num(cls):
print(cls.account_count)
kim = Account("김민수", 100)
lee = Account("이민수", 100)
kim.get_account_num()
#274
import random
class Account:
account_count = 0
def __init__(self, name, balance):
self.name = name
self.balance = balance
self.bank = "SC은행"
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
Account.account_count +=1
def get_account_num(cls):
print(cls.account_count)
def deposit(self, amount):
if amount >= 1:
self.balance += amount
#275
import random
class Account:
account_count = 0
def __init__(self, name, balance):
self.name = name
self.balance = balance
self.bank = "SC은행"
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
Account.account_count += 1
def get_account_num(cls):
print(cls.account_count)
def deposit(self, amount):
if amount >= 1:
self.balance += amount
def withdraw(self, amount):
if self.balance > amount:
self.balance -= amount
k = Account("kim", 100)
k.deposit(100)
k.withdraw(90)
print(k.balance)
#276
import random
class Account:
account_count = 0
def __init__(self, name, balance):
self.name = name
self.balance = balance
self.bank = "SC은행"
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
Account.account_count += 1
def get_account_num(cls):
print(cls.account_count)
def deposit(self, amount):
if amount >= 1:
self.balance += amount
def withdraw(self, amount):
if self.balance > amount:
self.balance -= amount
def display_info(self):
print("은행이름: ", self.bank)
print("예금주: ", self.name)
print("계좌번호: ", self.account_number)
print("잔고: ", self.balance)
p = Account("파이썬", 10000)
p.display_info()
#277
import random
class Account:
account_count = 0
def __init__(self, name, balance):
self.deposit_count = 0
self.name = name
self.balance = balance
self.bank = "SC은행"
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
Account.account_count += 1
def get_account_num(cls):
print(cls.account_count)
def deposit(self, amount):
if amount >= 1:
self.balance += amount
self.deposit_count += 1
if self.deposit_count % 5 == 0:
self.balance = (self.balance * 1.01)
def withdraw(self, amount):
if self.balance > amount:
self.balance -= amount
def display_info(self):
print("은행이름: ", self.bank)
print("예금주: ", self.name)
print("계좌번호: ", self.account_number)
print("잔고: ", self.balance)
p = Account("파이썬", 10000)
p.deposit(10000)
p.deposit(10000)
p.deposit(10000)
p.deposit(5000)
p.deposit(5000)
print(p.balance)
#278
import random
class Account:
account_count = 0
def __init__(self, name, balance):
self.deposit_count = 0
self.name = name
self.balance = balance
self.bank = "SC은행"
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
Account.account_count += 1
def get_account_num(cls):
print(cls.account_count)
def deposit(self, amount):
if amount >= 1:
self.balance += amount
self.deposit_count += 1
if self.deposit_count % 5 == 0:
self.balance = (self.balance * 1.01)
def withdraw(self, amount):
if self.balance > amount:
self.balance -= amount
def display_info(self):
print("은행이름: ", self.bank)
print("예금주: ", self.name)
print("계좌번호: ", self.account_number)
print("잔고: ", self.balance)
data = []
k = Account("KIM", 10000000)
l = Account("LEE", 10000)
p = Account("PARK", 10000)
data.append(k)
data.append(l)
data.append(p)
print(data)
#279
import random
class Account:
account_count = 0
def __init__(self, name, balance):
self.deposit_count = 0
self.name = name
self.balance = balance
self.bank = "SC은행"
# 3-2-6
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
Account.account_count += 1
def get_account_num(cls):
print(cls.account_count)
def deposit(self, amount):
if amount >= 1:
self.balance += amount
self.deposit_count += 1
if self.deposit_count % 5 == 0:
self.balance = (self.balance * 1.01)
def withdraw(self, amount):
if self.balance > amount:
self.balance -= amount
def display_info(self):
print("은행이름: ", self.bank)
print("예금주: ", self.name)
print("계좌번호: ", self.account_number)
print("잔고: ", self.balance)
data = []
k = Account("KIM", 10000000)
l = Account("LEE", 10000)
p = Account("PARK", 10000)
data.append(k)
data.append(l)
data.append(p)
for c in data:
if c.balance >= 1000000:
c.display_info()
#280
import random
class Account:
account_count = 0
def __init__(self, name, balance):
self.deposit_count = 0
self.deposit_log = []
self.withdraw_log = []
self.name = name
self.balance = balance
self.bank = "SC은행"
num1 = random.randint(0, 999)
num2 = random.randint(0, 99)
num3 = random.randint(0, 999999)
num1 = str(num1).zfill(3)
num2 = str(num2).zfill(2)
num3 = str(num3).zfill(6)
self.account_number = num1 + '-' + num2 + '-' + num3
Account.account_count += 1
def get_account_num(cls):
print(cls.account_count)
def deposit(self, amount):
if amount >= 1:
self.deposit_log.append(amount)
self.balance += amount
self.deposit_count += 1
if self.deposit_count % 5 == 0:
self.balance = (self.balance * 1.01)
def withdraw(self, amount):
if self.balance > amount:
self.withdraw_log.append(amount)
self.balance -= amount
def display_info(self):
print("은행이름: ", self.bank)
print("예금주: ", self.name)
print("계좌번호: ", self.account_number)
print("잔고: ", self.balance)
def withdraw_history(self):
for amount in self.withdraw_log:
print(amount)
def deposit_history(self):
for amount in self.deposit_log:
print(amount)
k = Account("Kim", 1000)
k.deposit(100)
k.deposit(200)
k.deposit(300)
k.deposit_history()
k.withdraw(100)
k.withdraw(200)
k.withdraw_history()
|
cs |
초보자를 위한 파이썬 300제 (281~290)
위키독스
온라인 책을 제작 공유하는 플랫폼 서비스
wikidocs.net
|
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
|
#281
class 차:
def __init__(self, 바퀴, 가격):
self.바퀴 = 바퀴
self.가격 = 가격
car = 차(2, 1000)
print(car.바퀴)
print(car.가격)
#282
class 차:
def __init__(self, 바퀴, 가격):
self.바퀴 = 바퀴
self.가격 = 가격
class 자전차(차):
pass
#283
class 차:
def __init__(self, 바퀴, 가격):
self.바퀴 = 바퀴
self.가격 = 가격
class 자전차(차):
def __init__(self, 바퀴, 가격):
self.바퀴 = 바퀴
self.가격 = 가격
bicycle = 자전차(2, 100)
print(bicycle.가격)
#284
class 차:
def __init__(self, 바퀴, 가격):
self.바퀴 = 바퀴
self.가격 = 가격
class 자전차(차):
def __init__(self, 바퀴, 가격, 구동계):
super().__init__(바퀴, 가격)
#차.__init__(self, 바퀴, 가격)
self.구동계 = 구동계
bicycle = 자전차(2, 100, "시마노")
print(bicycle.구동계)
print(bicycle.바퀴)
#285
class 차:
def __init__(self, 바퀴, 가격):
self.바퀴 = 바퀴
self.가격 = 가격
class 자동차(차):
def __init__(self, 바퀴, 가격):
super().__init__(바퀴, 가격)
def 정보(self):
print("바퀴수 ", self.바퀴)
print("가격 ", self.가격)
car = 자동차(4, 1000)
car.정보()
#286
class 차:
def __init__(self, 바퀴, 가격):
self.바퀴 = 바퀴
self.가격 = 가격
def 정보(self):
print("바퀴수 ", self.바퀴)
print("가격 ", self.가격)
class 자동차(차):
def __init__(self, 바퀴, 가격):
super().__init__(바퀴, 가격)
class 자전차(차):
def __init__(self, 바퀴, 가격, 구동계):
super().__init__(바퀴, 가격)
self.구동계 = 구동계
bicycle = 자전차(2, 100, "시마노")
bicycle.정보()
#287
class 차:
def __init__(self, 바퀴, 가격):
self.바퀴 = 바퀴
self.가격 = 가격
def 정보(self):
print("바퀴수 ", self.바퀴)
print("가격 ", self.가격)
class 자동차(차):
def __init__(self, 바퀴, 가격):
super().__init__(바퀴, 가격)
class 자전차(차):
def __init__(self, 바퀴, 가격, 구동계):
super().__init__(바퀴, 가격)
self.구동계 = 구동계
def 정보(self):
super().정보()
print("구동계 ", self.구동계)
bicycle = 자전차(2, 100, "시마노")
bicycle.정보()
#288
class 부모:
def 호출(self):
print("부모호출")
class 자식(부모):
def 호출(self):
print("자식호출")
나 = 자식()
나.호출()
#289
class 부모:
def __init__(self):
print("부모생성")
class 자식(부모):
def __init__(self):
print("자식생성")
나 = 자식()
#290
class 부모:
def __init__(self):
print("부모생성")
class 자식(부모):
def __init__(self):
print("자식생성")
super().__init__()
나 = 자식()
|
cs |
'Python & SQL > Python Problems' 카테고리의 다른 글
| [점프 투 파이썬] 02장 연습 문제 풀이 (0) | 2021.04.16 |
|---|---|
| [초보 300제] 파이썬 파일 입출력과 예외 처리(291~300) 풀이 (0) | 2021.04.12 |
| [초보 300제] 파이썬 모듈(241~250) 풀이 (0) | 2021.04.11 |
| [초보 300제] 파이썬 함수(201~240) 풀이 (0) | 2021.04.06 |
| [초보 300제] 파이썬 반복문(131~200) 풀이 (0) | 2021.04.03 |