TEKsystemsOA #1
Message Objects (OOP)
估计简单评测数据准备中,可先阅读题面
考点(AI 标注)迭代器设计
Complete the Message class to handle processing of messages between a sender and a receiver. Implement the following methods:
class Message(object):
def __init__(self, message: str, sender: int, receiver: int) -> None: pass
def __str__(self) -> str: pass
def __eq__(self, o: object) -> bool: pass
__init__: store the message, sender, receiver as instance variables.__str__: return the message text (without sender/receiver).__eq__: two messages are equal iff their message attributes (text) are the same. Sender and receiver do not affect equality.
Example
message1 = Message("Hello", 1, 2)
message2 = Message("Hello World", 3, 2)
message3 = Message("Hello", 2, 1)
print(message1) # Hello
message1 == message2 # False
message1 == message3 # True
Constraints
- Maximum number of messages ≤ 50
- Maximum message length ≤ 100 words
- Sender and Receiver are integers between 0 and 100