영어 에세이를 적는 원칙중에, 모든 글은 쉽게 쓰는 방법이 있으면 그렇게 써야한다 원칙이 있습니다.

코딩도 비슷한 원칙을 갖고있습니다. 

어제 밤에 블로그 포스팅을 하고 오늘 아침에 내가 한 코드를 봤었는데요.

 

너무 부족한 부분이 많이 보여서 

다시 수정을 했어요, 왜 당장 처음할때는 보이지 않았던 문제들이 이제와서 보이는건지 참 .... 

 

class Labotory:
    def __init__(self, name, Idnumber, origin):
        self.name = name
        self.number = Idnumber
        self.origin = origin
     
    def introduce(self):  # Corrected method name from lntroduce to introduce
        print(f'My name is {self.name} and from {self.origin}')

   
Labomen = [Labotory("Okabe_rintarou", "001", "Japan"),
           Labotory("Shiina_Mayuuri", "002", "Japan")]
           

class Microwave:
    def __init__(self):
        self.is_on = False
        self.messages = []  # Added messages attribute

    def turn_on(self):
        self.is_on = True
        print("Microwave is now on")

    def turn_off(self):
        self.is_on = False
        print("Microwave is now off")
   
    def receive_message(self, sender, message):
        print(f"{self.__class__.__name__} received message from {sender.name}: {message}")
        self.messages.append(message)

class CrtTv:
    def __init__(self):
        self.is_on = False
   
    def turn_on(self):
        self.is_on = True
        print("The CRT TV is now on")

    def turn_off(self):
        self.is_on = False
        print("The CRT TV is now off")

class DivergenceMeter:
    def __init__(self):
        self.current_divergent_value = 0.571040
        self.divergent_value_log = []

    def change_value(self):
        self.current_divergent_value += 0.003
        print(f"Divergence Meter changed to {self.current_divergent_value}")
        self.divergent_value_log.append(self.current_divergent_value)

class GameStory:
    def __init__(self, labomen, microwave, crt_tv, divergence_meter):
        self.labomen = labomen
        self.microwave = microwave
        self.crt_tv = crt_tv
        self.divergence_meter = divergence_meter

    def send_message_to_change_divergence_meter(self):
        if self.microwave.is_on and self.crt_tv.is_on:
            print(f"{self.labomen.name}: I want to change the world")
            message = "elp, psy, kongoroo"
            self.microwave.receive_message(self.labomen, message)
            self.divergence_meter.receive_message(self.labomen, message)
            self.divergence_meter.change_value()
        else:
            print("Seems like nothing has changed.....")
   
    def show_the_divergence_meter_history(self):
        print("Divergence meter history:")
        for value in self.divergence_meter.divergent_value_log:
            print(value)

# Create instances
microwave = Microwave()
crt_tv = CrtTv()
divergence_meter = DivergenceMeter()

# Instantiate GameStory with the first Labotory instance
game_story = GameStory(Labomen[0], microwave, crt_tv, divergence_meter)

# Call the method on the GameStory instance
game_story.send_message_to_change_divergence_meter()

# Show the divergence meter history
game_story.show_the_divergence_meter_history()

#Let's make it happen

microwave.is_on()
crt_tv.is_on()
game_story.send_message_to_change_divergence_meter()

+ Recent posts