-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.py
90 lines (65 loc) · 1.93 KB
/
object.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-
"""Week_6_assignment.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/
## Week 6 - Assignment
___
"""
class Messenger:
def __init__(self, user_name, user_phone_number):
self.user_name = user_name
self.user_phone_number = user_phone_number
self.messagebox = []
# define three variables
def info(self):
print("User : ", self.user_name, "/ Phone number : ", self.user_phone_number)
# print user name and phone number
def send(self, target_user, message):
self.message = message
target_user.receive(self.message)
# send a message to target_user
def receive(self, message):
self.message = message
self.messagebox.append(self.message)
# receive a message and store the message to the user message box
def read_latest(self):
if self.messagebox == []:
print('empty')
else:
print(self.messagebox)
def read_recent(self , N):
self.N = N
if self.messagebox == []:
print('empty')
else:
print(self.messagebox[len(self.messagebox)-N: ])
def delete(self, option):
self.option = option
if option == 'all':
self.messagebox = []
elif option == 'last':
del self.messagebox[-1]
else:
print("You choose the worng option.")
print("Please choose right option either 'all' or 'last'")
#실제 예시 실행
sam = Messenger('Sam', '010-7777-7777')
peter = Messenger('Peter', '010-9999-1111')
sam.info()
peter.info()
sam.send(peter, "Hello")
peter.read_latest()
peter.send(sam, "What's up?")
sam.read_latest()
for i in range(1, 10):
peter.send(sam, i)
sam.read_recent(3)
sam.delete('last')
sam.read_recent(3)
sam.delete('last')
sam.delete('last')
sam.read_latest()
sam.delete('all')
sam.read_latest()
sam.read_recent(3)