Build an Email Simulator - Step 35

Tell us what’s happening:

I have tried alternative codes. There is no warning in the console, but the code does not pass.

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)

    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'{i}. {email}')

    def read_email(self, index):
        if not self.emails:
            print('Inbox is empty.\n')
            return
        actual_index = index - 1
        if actual_index < 0 or actual_index >= len(self.emails):
            print("Invalid email number.\n")
            return
            email =[valid]
            email = self.emails[actual_index]
            email.display_full_email()
        
        
            
# User Editable Region
        
# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36

Challenge Information:

Build an Email Simulator - Step 35

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-email-simulator/68dfc5f71dc2a6d65091a39c.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @Tsirha,

Can the lines of code after the return ever be processed? Were you asked to create an email variable?

Happy coding

The console is clear I get this message : You should access the email at actual_index in the self.emails list and call its display_full_email method.

I have removed the email calls as suggested :slight_smile: class Inbox:

def \__init_\_(self):

    self.emails = \[\]

    self.emails\[actual_index\]

    display_full_email()

display_full_email() is a method, how do you use methods?

This is the entire code now. I have used all suggestion same call.

class Inbox:

def \__init_\_(self):

    self.emails = \[\]



def receive_email(self, email):

    self.emails.append(email)



def list_emails(self):

    print('\\nYour Emails:')

    if not self.emails:

        print("Your inbox is empty.\\n")

        return

    

    for i, email in enumerate(self.emails, start=1):

        print(f"{i}. {email}")



def read_email(self, index):

    if not self.emails:

        print('Inbox is empty.\\n')

        return

    

    actual_index = index - 1

    

    

    if actual_index < 0 or actual_index >= len(self.emails):

        print("Invalid email number.\\n")

        return

    

    

    self.emails\[actual_index\]

def display_full_email():

    pass

Why are you creating a display_full_email method in the Inbox class?

What kind of object is self.emails[actual_index] giving you where you already have that method?

Happy coding

I have advanced to Step 42:

The code : class Inbox:

def \__init_\_(self):

   self.timestamp

datetime.datetime.now()

is not working.

please create a new topic for that

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.