728x90
반응형
class Account() :
account_cnt = 0
def __init__(self, num, balance) : #외부에서 받는다는 뜻
self.__num = num #계좌번호 인스턴스 객체별로 하나씩 만들어짐
self.__balance = balance #잔액
Account.account_cnt = Account.account_cnt + 1
def set_num(self, num) :
self.__num = num
def get_num(self) :
return self.__num
def get_balance(self) :
return self.__balance
def set_balance(self, balance) :
self.__balance = balance
#입금
def deposit(self, money) :
self.__balance = self.__balance + money
# return a
#출금
def withdraw(self, money) :
if(self.__balance < money) :
print('잔액이 부족합니다.')
else :
self.__balance = self.__balance - money
#송금
def transfer(self, money, other) :
if(self.__balance < money) :
print('잔액이 부족합니다.')
else :
self.__balance = self.__balance - money
other.__balance= other.__balance + money
other_balance = other.get_balance()
other.set_balance(other_balance + money)
def __eq__(self, other_rect) : #같은지 확인
return self.m_area() == other_rect.m_area()
# self.withdraw
# other.deposit
# def fiCheak(self, other_rect) :
# if self.get_num = other_rect.get_num
#정보 출력
def print_info(self) :
print('계좌번호 %d번 잔액 %d원 입니다.'%(self.__num, self.__balance))
#계좌 갯수 출력
@classmethod
def print_account_cnt(cls):
print(cls.account_cnt)
import random
user1 = Account(110453, 150000) #객체생성
user2 = Account(2530913,300000)
user3 = Account(234, 100000)
en = [user1, user2, user3]
# 메뉴 선택
a = int(input('원하시는 버튼을 입력하세요. 1.계좌만들기 2. 입금 3. 출금 4. 송금 '))
if a >= 5 :
print('1 ~ 4까지의 숫자만 입력해주세요.')
#은행 계좌 넣는 곳
elif a == 1 :
num = random.randint(1,100000) # 1부터 100000까지
print('%d라는 계좌번호가 개설되었습니다.' %num)
en.append(num) # 랜덤으로 받은 num을 객체로 생성하는 방법을 모르겠음.
elif a == 2 :
i = int(input('본인의 계좌번호를 입력하세요.')) #입금
if i == 110453 : #리스트 안에 계좌번호가 같은지 확인하는 방법을 모르겠음
u = int(input('입금하실 금액을 기입해주세요.'))
user1.deposit(u) # 같은 계좌에 금액을 더하는 코드를 모르겠음.
print('고객님의 잔액은 %d입니다.' %(user1.get_balance()))
elif i == 2530913 :
u = int(input('입금하실 금액을 기입해주세요.'))
user2.deposit(u) # 같은 계좌에 금액을 더하는 코드를 모르겠음.
print('고객님의 잔액은 %d입니다.' %(user2.get_balance()))
elif i == 234 :
u = int(input('입금하실 금액을 기입해주세요.'))
user3.deposit(u) # 같은 계좌에 금액을 더하는 코드를 모르겠음.
print('고객님의 잔액은 %d입니다.' %(user3.get_balance()))
else :
print('잘못된 계좌번호를 기입하셨습니다. 다시시도해주세요.')
elif a == 3 :
i = int(input('본인의 계좌번호를 입력하세요.')) #출금
if i == 110453 : #리스트 안에 계좌번호가 같은지 확인하는 방법을 모르겠음
u = int(input('출금하실 금액을 기입해주세요.'))
user1.withdraw(u) # 같은 계좌에 금액을 더하는 코드를 모르겠음.
print('고객님의 잔액은 %d입니다.' %(user1.get_balance()))
elif i == 2530913 :
u = int(input('출금하실 금액을 기입해주세요.'))
user2.withdraw(u) # 같은 계좌에 금액을 더하는 코드를 모르겠음.
print('고객님의 잔액은 %d입니다.' %(user2.get_balance()))
elif i == 234 :
u = int(input('출금하실 금액을 기입해주세요.'))
user3.withdraw(u) # 같은 계좌에 금액을 더하는 코드를 모르겠음.
print('고객님의 잔액은 %d입니다.' %(user3.get_balance()))
else :
print('잘못된 계좌번호를 기입하셨습니다. 다시시도해주세요.')
elif a == 4 :
t = int(input('본인의 계좌번호를 입력하세요.'))
if t == 110453 :
u = int(input('송금하실 계좌번호를 입력하세요.'))
v = int(input('송금하실 금액을 기입해주세요.'))
user1.transfer(v,user2) #송금할 계좌의 transfer 적용을 모르겠음
print('송금한 후 잔액 %d입니다.' %user1.get_balance())
elif t == 234 :
u = int(input('송금하실 계좌번호를 입력하세요.'))
v = int(input('송금하실 금액을 기입해주세요.'))
user3.transfer(v,user2) #송금할 계좌의 transfer 적용을 모르겠음
print('송금한 후 잔액 %d입니다.' %user3.get_balance())
else :
print('잘못된 계좌번호입니다. 다시시도해주세요.')
고객님의 잔액은 95500입니다.
user1 = Account(1) #객체생성
user2 = Account(2)
# print(user1.get_num()) num print
# print(user1.get_balance()) balance print
user1.deposit(9)
print(user1.get_balance())
# user1.deposit(3) 한번 더 하면 추가됨
# print(user1.get_balance())
user1.print_info()
# user1.withdraw(1) -1 and
# print(user1.get_balance()) than print
# print(user1.balance) __라는 것은 privte이라는 뜻
# print(user1.num) 접근 할 경우 안되게끔
Account.print_account_cnt()
Account.print_account_cnt()
user1.transfer(2, user2)
150012
계좌번호 110453번 잔액 150012원 입니다.
14
14
class Rectangle () :
def __init__(self, garo, sero) :
self.__garo = garo
self.__sero = sero
def get_garo(self) :
return self.__garo
def set_garo(self) :
self.__garo = garo
def get_sero(self) :
return self.__sero
def set_garo(self) :
self.__saro = sero
def __str__(self) :
return '가로는 %d '% self.__garo
def __eq__(self, other_rect) : #같은지 확인
return self.m_area() == other_rect.m_area()
def __gt__(self, other_rect) : # 큰지 확인
return self.m_area() < other_rect.m_area()
def __le__(self, other_rect) : #작거나 같다 확인
return self.m_area <= other_rect.m_area()
def __lt__(self, other_rect) :
return self.m_area() > other_rect.m_area()
def __ge__(self, other_rect): #크거나 같은지 확인
return self.m_area() <= other_rect.m_area()
def m_round(self) :
return (self.__garo + self.__sero) * 2
def m_area(self) :
return (self.__garo * self.__sero)
fi1 = Rectangle(3, 4)
fi2 = Rectangle(4, 5)
fi3 = Rectangle(5, 6)
fi4 = Rectangle(6, 7)
fi5 = Rectangle(7, 8)
# rect_list = [fi1, fi2, fi3, fi4, fi5]
rect_list = list()
rect_list.append(fi1)
rect_list.append(fi2)
rect_list.append(fi3)
rect_list.append(fi4)
rect_list.append(fi5)
rect_list[0].m_area()
for z in rect_list :
print(z.m_area())
print(fi1 == fi2)
print(fi1 >= fi2)
print(fi1 >= fi2)
# print(rect_list, type(rect_list))
# print(fi1,fi2)
# print(fi1.m_round())
# print(fi1.m_area())
# print(fi2.m_round())
# print(fi2.m_area())
12
20
30
42
56
False
True
True
# import math
# # dir(math)
# math.atan(3)
# import datetime 1번째 방법
# x = datetime.datetime.now()
# print(x)
from datetime import datetime #2번째 방법
x = datetime.now()
print(x)
print(x.year)
print(x.month)
print(x.day)
s = x.strftime('%Y/%m/%d')
print(s)
# y = datetime.strptime("2022-01-03" , '%y-%m-%d')
# print(type(y))
2022-01-03 15:51:43.242501
2022
1
3
2022/01/03
import platform
x = platform.system()
print(x)
Windows
import random
num = random.randint(1,100) # 1부터 100까지
print(num)
num = random.random()
print(num)
num = random.randrange(1, 7, 2)
print(num)
xyz = ['a','b','c','d']
random.shuffle(xyz)
x = random.choice(xyz)
print(x)
98
0.777822968364066
3
a
!pip install camelcase
Requirement already satisfied: camelcase in c:\users\bit\anaconda3\lib\site-packages (0.2)
import camelcase
# c = camelacse.Camelcase()
#c = cc.CamelCase()
c = camelcase.CamelCase()
txt = "hello wofld"
print(c.hump(txt))
Hello Wofld
# ! pip list
import json
json_string = '''{ "name" : "John",
"age":30,
"city" : "New York"}'''
python_dict = json.loads(json_string)
print(type(python_dict), python_dict)
print(python_dict["age"])
json_string = json.dumps(python_dict) #json 문자열로 변환
print(json_string, type(json_string))
{'name': 'John', 'age': 30, 'city': 'New York'}
30
{"name": "John", "age": 30, "city": "New York"}
728x90
반응형
'IT To do and To was' 카테고리의 다른 글
22년 1월 5일_크롤링, 다시 학교 수업 시작 (0) | 2022.01.05 |
---|---|
22년 1월 4일_헐, 너무 행복해, Json (0) | 2022.01.04 |
22년 1월 1일_모든 과목 시험, 막내삼촌, 최. 악의 언니 남친 (0) | 2022.01.02 |
21년 12월 30일_set, 딕셔너리, list, 매개변수=파라미터, 아규먼트=인수, 클래스의 첫 시작 (0) | 2021.12.30 |
21년 12월 29일_매개변수, tuple, break, uppend, 자료구조 (0) | 2021.12.29 |