Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 안드로이드스튜디오
- 정처기
- 안드로이드
- 자바연산자
- 바텀네비게이션
- 정처기운영체제
- 파이썬예제
- 업다운게임코드
- 운영체제목적
- 운영체제종류
- 자바예제
- 파이썬공부
- bottomnavigation
- 데이터베이스
- 컴퓨터일반
- 코딩
- 스누핑
- 파이썬배열
- 파이썬리스트
- 코딩공부
- int크기
- 엑티비티
- 파이썬
- 정보처리산업기사
- 정처산기
- 백준
- java
- androidstudio
- 자바
- 파이썬배열예제
Archives
- Today
- Total
발전을 위한 기록
[국민내일배움][Python] Day10 본문
2022/09/15
배운 내용을 복습하기 위한 기록용 게시물입니다✍️✍️
https://github.com/riwltnchgo0625/PythonWorkspace
9:00 ~ 12:50
오버라이딩, 상속, super()
class Shape:
def __init__(self, num1, num2): # 초기화자, 생성자 ->객체를 생성할때 자동으로 실행 메서드
self.width = num1
self.height = num2
def area(self):
area = self.width * self.height
print('면적{}'.format(area))
def test(self):
print('부모 클래스의 test메소드')
class Square(Shape):
shape1 = Shape(10, 20) # 클래스로 객체(인스턴스)를 생성
shape1.area()
def subArea(self):
print('자식 클래스의 메서드 호출')
sum = self.width + self.height
print(sum)
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
def circleArea(self):
area = self.radius * self.radius * 3.14
print(area)
def area(self):
print('부모 클래스의 area 메서드를 오버 라이딩 하였습니다.')
def test(self):
print('자식의 test 메서드를 오버라이딩 하였습니다.')
super().test() # 부모의 test메소드를 호출
class Triangle(Shape):
def __init__(self, number, width, height):
self.number = number
super().__init__(width, height)
# self.width = width
# self.height = height
def tri(self):
print('저는 삼각형 입니다. number값은 {}입니다'.format(self.number))
tri1 = Triangle(1000, 20, 30)
tri1.area()
tri1.tri()
print('-------------------')
square1 = Square(50, 60)
square1.area()
square1.subArea()
print('-------------------')
circle1 = Circle(10)
circle1.circleArea()
circle1.area()
circle1.test()
class Car():
def __init__(self, name):
self.name = name
def run(self):
print('{}가 달립니다.'.format(self.name))
class Truck(Car):
def __init__(self, name, capacity):
super().__init__(name)
self.capacity = capacity
def load(self):
print('{}kg짐을 실었습니다.'.format(self.capacity))
truck1 = Truck('트럭', 1200)
truck1.run()
truck1.load()
조건제시법
# 한변의 길이가 1~10인 정사각형의 넓이를 원소로 가지는 리스트를 만드시오
areas = [] # 빈 리스트 생성
for i in range(1, 11): # range(1,11) -> [1,2,3,4,5,6,7,8,9,10]
# area = i* i
# areas.append(area)
areas = areas + [i * i]
print(areas)
print('--------------------------')
areas2 = [i * i for i in range(1, 11)]
print(areas2)
print('--------------------------')
areas3 = []
for i in range(1, 11):
if i % 2 == 0:
areas3 = areas3 + [i * i]
print(areas3)
print('---------------------------')
areas4 = [i * i for i in range(1, 11) if i % 2 == 0]
print(areas4)
print('---------------------------')
tupleList1 = [(i, j) for i in range(1, 11) for j in range(11, 21)]
print(tupleList1) # 100개의 튜플이 원소인 리스트 생성
print('---------------------------')
list1 = [i for i in range(1, 101) if i % 8 == 0]
print(list1)
print('---------------------------')
# 구구단의 결과값을 원소로 가지는 리스트를 리스트 내포를 사용하여 작성
list2 = [(i * j) for i in range(2, 10) for j in range(1, 10)]
print(list2)
13:50 ~ 17:40
students = ['태연', '성진', '하늘', '정현', '진우']
for number, name in enumerate(students):
print('{}번의 이름은 {}입니다'.format(number, name))
print('-----------------------------')
stud_dict = {'{}번'.format(number + 1): name for number, name in enumerate(students)}
print(stud_dict)
print('------------------------------')
scores = [85, 90, 100, 75, 83]
for x, y in zip(students, scores):
print(x, y)
score_dict = {x: y for x, y in zip(students, scores)}
print(score_dict)
print('------------------------------')
product_list = ['풀', '가위', '크레파스']
price_list = [800, 2500, 5000]
price_dict = {x: y for x, y in zip(product_list, price_list)}
print(price_dict)
import datetime
now_time = datetime.datetime.now()
print(type(now_time)) # datetime 모듈안의 dattime 클래스로 만든 객체(인스턴스)
new_time = now_time.replace(year=2019, month=10, day=25)
print(new_time)
print(now_time)
print('---------------------------------------------')
time1 = datetime.datetime(2022, 8, 25)
# datetime 모듈안의 datetime 클래스로 객체 생성
result_time = now_time - time1
print(result_time)
print('---------------------------------------------')
print(type(result_time))
print(type(time1))
print('---------------------------------------------')
print(result_time.days)
print(result_time.seconds)
print('---------------------------------------------')
print('우리가 공부를 시작한지 {}일 {}시간 지났습니다!'.format(result_time.days, result_time.seconds // 60 // 60))
print('---------------------------------------------')
def days_until_christmas():
christmas_2022 = datetime.datetime(2022, 12, 25)
days = (christmas_2022 - datetime.datetime.now()).days
return days
print('{}일'.format(days_until_christmas()))
print('---------------------------------------------')
import datetime
hundred_days = datetime.timedelta(days=100)
print(datetime.datetime.now() + hundred_days)
print('--------------------------------------')
hundred_after = datetime.datetime.now().replace(hour=9, minute=0, second=0) + hundred_days
# print(hundred_after)
print('{}년 {}월 {}일'.format(hundred_after.year, hundred_after.month, hundred_after.day))
728x90