在我的代码上使用我的当前设置;如何仅输出False对象(“hasBeenRead=False”)
#An SMS Simulation
SMSStore = []
unreadMessage = []
class SMSMessage(object):
def __init__(self, messageText, fromNumber):
self.hasBeenRead = False
self.messageText = messageText
self.fromNumber = fromNumber
def markAsRead(self, hasBeenRead):
hasBeenRead = True
def add_sms(self):
newMessage = (self.hasBeenRead, self.messageText, self.fromNumber)
return SMSStore.append(newMessage)
def get_count(self):
return len(SMSStore)
def get_message(self, q):
print (SMSStore[q][1])
self.get_hasBeenRead()
def get_hasBeenRead(self):
self.hasBeenRead = True
def get_unread_messages(SMSStore):
counter = 0
if SMSStore[counter][0] == False:
print "From: " + SMSStore[counter][2]
print "Message: " + SMSStore[counter][1]
counter = counter +1
def remove(self, i):
return SMSStore.remove(i)
#sample = SMSMessage("Hello friend!", 0742017560)
userChoice = ""
while userChoice != "quit":
userChoice = raw_input("What would you like to do - read/send/quit?")
if userChoice == "read":
i = int((raw_input("Please enter which messsage number you want to read: ")))
messageText = "null"
fromNumber = "null"
newObject1 = SMSMessage(messageText, fromNumber)
newObject1.get_message(i)
readUnread = raw_input("Would you like to read the unread messages: yes/no?")
if readUnread == "yes":
newObject1.get_unread_messages()
else:
print "All messages have been read"
elif userChoice == "send":
messageText = raw_input("Please type in your message: ")
fromNumber = raw_input("Please type in the number it was sent from ")
newObject = SMSMessage(messageText, fromNumber)
newObject.add_sms()
print str(newObject.get_count()) + " is now the new length of the list"
elif userChoice == "quit":
print "Goodbye"
else:
print "Oops - incorrect input"
正如您所看到的,我是一个安静的编码初学者,但使用我的设置,是否可以只输出列表中包含False的对象
目前没有回答
相关问题 更多 >
编程相关推荐