Day 016

AWESOMee·2022년 2월 5일
0

Udemy Python Bootcamp

목록 보기
16/64
post-thumbnail

Udemy Python Bootcamp Day 016

OOP: Object Oriented Programming

from turtle import Turtle, Screen
timmy = Turtle()  # timmy: Object / Turtle: Class
print(timmy)
timmy.shape("turtle")
timmy.color("aquamarine2")
timmy.forward(100)

my_screen = Screen()
print(my_screen.canvheight)  # my_screen: Object / canvheight: Attribute
my_screen.exitonclick()

세상에.. 이거 입력했더니 창이 하나 띄워지면서 민트색 거북이가 나타나 움직이는 걸 보고 입을 틀어막고 감격함..

from prettytable import PrettyTable

table = PrettyTable()  # Pascal case
table.add_column("Pokemon Name", ["Pikachu", "Squirtle", "Charmander"])
table.add_column("Type", ["Electric", "Water", "Fire"])

print(table)

""" # output
+--------------+----------+
| Pokemon Name |   Type   |
+--------------+----------+
|   Pikachu    | Electric |
|   Squirtle   |  Water   |
|  Charmander  |   Fire   |
+--------------+----------+
"""


table.align = "l"
print(table)
""" # output
+--------------+----------+
| Pokemon Name | Type     |
+--------------+----------+
| Pikachu      | Electric |
| Squirtle     | Water    |
| Charmander   | Fire     |
+--------------+----------+
"""

Coffee Machine in OOP

from menu import Menu, MenuItem
from coffee_maker import CoffeeMaker
from money_machine import MoneyMachine

money_machine = MoneyMachine()
coffee_maker = CoffeeMaker()
menu = Menu()

is_on = True

coffee_maker.report()
money_machine.report()

while is_on:
    options = menu.get_items()
    choice = input(f"What would you like? ({options}): ")
    if choice == "off":
        is_on = False
    elif choice == "report":
        coffee_maker.report()
        money_machine.report()
    else:
        drink = menu.find_drink(choice)
        if coffee_maker.is_resource_sufficient(drink) and money_machine.make_payment(drink.cost):
            coffee_maker.make_coffee(drink)

쌤이 requirements, documentation 다 줬는데
예시까지 해놓고 어떻게 적용하는 지 몰라서 멍때리다가
바로 솔루션 보고 아하 함
근데 이렇게 아하 하는 경우에는 기억이 오래가지 못하는데,,
내일 다시 복습해야겠다..

그나저나 OOP 엄청 간단한거구나... 너무 신기해.. 물론 남이 만들어 놓은거 가져다 붙이기만 했지만....

profile
개발을 배우는 듯 하면서도

0개의 댓글