Build an Email Simulator - Step 31

Tell us what’s happening:

In my Python environment the code is working and giving the desired output. Formatting, '.'s and spaces seem correct. Please help

Your code so far

class Email:
    def __init__(self, sender, receiver, subject, body):
        self.sender = sender
        self.receiver = receiver
        self.subject = subject
        self.body = body
        self.read = False

    def mark_as_read(self):
        self.read = True

    def display_full_email(self):
        self.mark_as_read()
        print('\n--- Email ---')
        print(f'From: {self.sender.name}')
        print(f'To: {self.receiver.name}')
        print(f'Subject: {self.subject}')
        print(f'Body: {self.body}')
        print('------------\n')

    def __str__(self):
        status = 'Read' if self.read else 'Unread'
        return f"[{status}] From: {self.sender.name} | Subject: {self.subject}"
class User:
    def __init__(self, name):
        self.name = name
        self.inbox = Inbox()

    def send_email(self, receiver, subject, body):
        email = Email(sender=self, receiver=receiver, subject=subject, body=body)
        receiver.inbox.receive_email(email)

class Inbox:
    def __init__(self):
        self.emails = []

    def receive_email(self, email):
        self.emails.append(email)


# User Editable Region

    def list_emails(self):
        if not self.emails:
            print('Your inbox is empty.\n')
            return

        print('\nYour Emails:')
        for i,email in enumerate(self.emails, start=1):
            print(f'\n{i}. {email.__str__()}')
        

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15

Challenge Information:

Build an Email Simulator - Step 31

consider if you ever need to use __str__ explicitly

next consider where and if you are asked to use \n

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.