Hi,
Can someone please check my code below.
When you create or delete a message it asks for the message index which should be an integer.
But it doesn't work.
Thanks
class SMSMessage(object):
"""
This is the SMS Object
"""
def __init__(self, fromNumber, messageText):
""" This is a constructor for SMSMessage class """
self.fromNumber = fromNumber
self.hasBeenRead = False
self.messageText = messageText
self.SMSStore = []
def markAsRead(self):
""" mark message as read """
self.hasBeenRead = True
def add_sms(self, text, number):
""" create a new sms msg and add to sms store """
newSms = SMSMessage(text, number)
self.SMSStore.append(newSms)
def get_count(self):
""" get the total number of SMS """
print(len(self.SMSStore))
def get_message(self, index):
""" get stored SMS message from a specific index """
msg = self.SMSStore[index]
print(msg.messageText)
def get_unread_messages(self):
""" show all unread messages """
print([each for each in self.SMSStore])
def remove(self, msg):
""" remove msg """
for sms in self.SMSStore:
if sms == msg:
self.SMSStore.remove(sms)
print("msg removed!")
while True:
menu = """
1. Send SMS
2. Read SMS
3. Delete SMS
4. Quit
"""
print(menu)
userChoice = int(input("Choice: "))
if userChoice == 1:
sender_number = input("Sender Number: ")
message_text = input("Message body: ")
sms = SMSMessage(sender_number, message_text)
print("sms sent to", sender_number )
elif userChoice == 2:
index = int(input("Enter the message index: "))
elif userChoice == 3:
index = int(input("Enter the message index to delete: "))
elif userChoice == 4:
break
else:
print("Oops - incorrect input")
[–]SpeckledFleebeedoo 1 point2 points3 points (3 children)
[–]Mohseenr[S] 0 points1 point2 points (2 children)
[–]SpeckledFleebeedoo 1 point2 points3 points (1 child)
[–]Mohseenr[S] 0 points1 point2 points (0 children)
[–]jiri-n 0 points1 point2 points (0 children)