So I'm making this program where you can send notes to different users but when I try this:
It doesn't work. I write and send the note, but when I log in as the other user (still in the same execution) there is no received note.
import datetime
#initialise stuff
class Account:
def __init__(self, un, pw, notes, sent, received):
self.un = un
self.pw = pw
self.notes = notes
self.received = received
self.sent = sent
class SentNote:
def __init__(self, time, note, sender, recipient):
self.time = time
self.note = note
self.sender = sender
self.recipient = recipient
usernm = ""
passwd = ""
accounts = [Account("Eleeza", "Password", [], [], []), Account("User", "Password", [], [], [])]
signedinas = Account("", "", [], [], [])
#account signing up
def signmenu():
while True:
option = input("Sign [i]n or sign [u]p? >>> ").lower()
if option == "u":
signup()
if option == "i":
signin()
def signup():
usernm = input("Make a username >>> ")
passwd = input("Make a password >>> ")
accounts.append(Account(usernm, passwd, [], [], []))
def signin():
inun = input("Username? >>> ")
inpw = input("Password? >>> ")
for account in accounts:
if account.un == inun:
if account.pw == inpw:
print("\nSigned in!")
signedinas.un = account.un
signedinas.pw = account.pw
signedinas.notes = account.notes
appusage()
else:
print("Password is incorrect")
def appusage():
print("Welcome, " + signedinas.un + "!")
#ask what to do:
while True:
print("\nMain Menu\n")
print("[S]end notes")
print("[R]eceived notes ({0})".format(len(signedinas.received)))
print("Sign [O]ut")
whattodo = input("What would you like to do? >>> ").lower()
#send note
if whattodo == "s":
print("\nSend a note")
to = input("Username of who you're sending it to? >>> ")
send = SentNote(datetime.datetime.now(), "", to, signedinas.un)
print("Write your note:")
send.note = input("")
signedinas.sent.append(send)
for user in accounts:
if user.un == to:
user.received.append(send)
print("Sent note!")
if whattodo == "r":
print("View Received Notes")
for n in signedinas.received:
print("From " + n.sender + " at " + str(n.time))
print(n.note)
viewoption = input("[N]ext note [B]ack to main menu >>> ").lower()
if viewoption == "n":
continue
if viewoption == "b":
break
#sign out
if whattodo == "o":
print("See you soon!")
break
signmenu()