You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

class Friend:
def __init__(self, name):
self.name = name
self.invite = None
def set_invite(self, date):
self.invite = date
def show_invite(self):
if self.invite is not None:
return self.invite
return "No party..."
class Party:
def __init__(self, name):
self.name = name
self.friends = []
def add_friend(self, friend: Friend):
self.friends.append(friend)
def send_invites(self, date: str):
for friend in self.friends:
friend.set_invite("{}: {}".format(self.name, date))
def del_friend(self, friend: Friend):
self.friends.remove(friend)
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!")