본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 104

반응형

Q>

Each week you are meeting with your friends to spend some quality time together.

(매주 당신은 당신의 친구들과 만나서 양질의 시간을 함께 보내고 있습니다.)

Usually you're hanging out in a bar on Friday nights, or going out of town on Saturdays, or playing the board games on Sundays.

(보통 금요일 밤에는 술집에서 놀고, 토요일에는 도시를 벗어나거나 일요일 보드 게임을합니다.)

You want to simplify the process of gathering people and that's why you've decided to write a program which could automate this process.

(사람들을 모으는 과정을 단순화하기를 원하기 때문에이 과정을 자동화 할 수있는 프로그램을 작성하기로 결정한 것입니다. )
You should create the class Party(place) which will send the invites to all of your friends.

(모든 친구들에게 초대장을 보낼 수업 파티 (장소)를 만들어야합니다.)

Also you should create the class Friend and each friend will be an instance of this class.

(또한 Friend 클래스를 만들어야하며 각 친구는이 클래스의 인스턴스가됩니다. )
Sometimes the circle of friends is changing - new friends appear, the old ones disappear from your life (for example - move to another town).

(때로는 친구의 서클이 달라지고 있습니다. 새 친구가 나타나고, 오래된 친구가 사라집니다 (예 : 다른 마을로 이사).)

To form right connections you should create the Party class with the next methods:

(올바른 연결을 형성하려면 다음 메소드를 사용하여 Party 클래스를 만들어야한다. )


add_friend(Friend(name)) - add friend 'name' to the list of the 'observers' (people, which will get the invitations, when the new party is scheduled).

(add_friend (친구 (이름)) - '관측자'목록에 친구 '이름'을 추가하십시오 (새 파티가 열릴 때 초대장을받는 사람). )
del_friend(friend) - remove 'friend' from the 'observers' list.

(del_friend (친구) - '관측자'목록에서 '친구'를 삭제하십시오. )
send_invites() - send the invites with the right day and time to the each person on the list of 'observers'.

(send_invites () - '관찰자'목록에있는 각자에게 적절한 날짜와 시간의 초대장을 보냅니다.)


Class Friend should have the show_invite() method which returns the string with the last invite that the person has received with the right place, day and time.

(Class Friend에는 사람이받은 장소, 요일 및 시간과 함께 마지막으로 초대 한 문자열을 반환하는 show_invite () 메소드가 있어야합니다.)

The right place - is the 'place' which is given to the Party instance in the moment of creation. If the person didn't get any invites, this method should return - "No party..."

(올바른 장소 - 창조의 순간에 파티 인스턴스에 주어진 '장소'입니다. 그 사람이 초대장을받지 못했다면이 방법은 "No party ..."를 반환해야합니다. )
In this mission you could use the Observer design pattern.

(이 임무에서 Observer 디자인 패턴을 사용할 수 있습니다.)

 

Examples:

party = Party("Midnight Pub")
nick = Friend("Nick")
john = Friend("John")
lucy = Friend("Lucy")
chuck = Friend("Chuck")

party.add_friend(nick)
party.add_friend(john)
party.add_friend(lucy)
party.send_invites("Friday, 9:00 PM")
party.del_friend(nick)
party.send_invites("Saturday, 10:00 AM")
party.add_friend(chuck)

john.show_invite() == "Midnight Pub: Saturday, 10:00 AM"
lucy.show_invite() == "Midnight Pub: Saturday, 10:00 AM"
nick.show_invite() == "Midnight Pub: Friday, 9:00 PM"
chuck.show_invite() == "No party..."

 

Input: The Party class methods and friends.

         (Party 클래스의 메소드와 친구들.)

 

Output: The text of the last invite received by a person.

           (사람이 마지막으로 초대 한 텍스트입니다.)

 

How it is used: For automatic notifications mailout about the information changes to all of the observers.

                     (모든 옵서버에 대한 정보 변경에 대한 자동 알림 메일 아웃.)

 

Precondition: All friends' names will be different.

                   (모든 친구의 이름이 달라집니다.)

 

A>

'''
add_friend(Friend(name)) - add friend 'name' to the list of the 'observers' (people, which will get the invitations,
                           when the new party is scheduled).
del_friend(friend) - remove 'friend' from the 'observers' list.
send_invites() - send the invites with the right day and time to the each person on the list of 'observers'.
'''

class Friend:
    def __init__(self, name):
        self.name = name
        self.message = 'No party...'

    def invite(self, message):
        self.message = message

    def show_invite(self):
        return self.message

class Party:
    def __init__(self, place):
        self.place = place
        self.friends = []

    def add_friend(self, friend):
        self.friends.append(friend)

    def del_friend(self, friend):
        self.friends.remove(friend)

    def send_invites(self, date):
        for friend in self.friends:
            friend.invite(f'{self.place}: {date}')

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing

    party = Party("Midnight Pub")
    nick = Friend("Nick")
    john = Friend("John")
    lucy = Friend("Lucy")
    chuck = Friend("Chuck")

    party.add_friend(nick)
    party.add_friend(john)
    party.add_friend(lucy)
    party.send_invites("Friday, 9:00 PM")
    party.del_friend(nick)
    party.send_invites("Saturday, 10:00 AM")
    party.add_friend(chuck)

    assert john.show_invite() == "Midnight Pub: Saturday, 10:00 AM"
    assert lucy.show_invite() == "Midnight Pub: Saturday, 10:00 AM"
    assert nick.show_invite() == "Midnight Pub: Friday, 9:00 PM"
    assert chuck.show_invite() == "No party..."
    print("Coding complete? Let's try tests!")

 

O>

Coding complete? Let's try tests!

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 106  (0) 2019.06.27
Python Learn the basics Quiz 105  (0) 2019.06.25
Python Learn the basics Quiz 103  (0) 2019.06.25
Python Learn the basics Quiz 102  (0) 2019.06.25
Python Learn the basics Quiz 101  (0) 2019.06.25