---
id: 6853f4584f508e95cc7a9f4d
title: Step 30
challengeType: 20
dashedName: step-30
---

# --description--

Now you'll create a method to list all emails in the inbox. This method should handle the case where the inbox is empty and display a numbered list of emails when there are emails present.

Add a method called `list_emails` to your `Inbox` class that takes `self` as a parameter. First, create an `if` statement to check if the inbox is empty by testing the `emails` list. If it's empty, print the message `Your inbox is empty.\n`. Add a `return` statement to exit the method.

# --hints--

You should define a method named `list_emails` in the `Inbox` class that takes `self` as a parameter.

```js
({
    test: () => 
    {
        assert(runPython(`_Node(_code).find_class("Inbox").find_function("list_emails").has_args("self")`))
    }
})
```

You should check if `self.emails` is empty using `if not self.emails`.

```js
({
    test: () => 
    {
        assert(runPython(`_Node(_code).find_class("Inbox").find_function("list_emails").find_ifs()[0].find_conditions()[0].is_equivalent("not self.emails")`))
    }
})
```

You should print the message `Your inbox is empty.\n` if there are no emails.

```js
({
    test: () => 
    { 
        assert(runPython(`_Node(_code).find_class("Inbox").find_function("list_emails").find_ifs()[0].find_body()[0].is_equivalent("print('Your inbox is empty.\\\\n')")`))
    }
})
```

You should have a `return` statement at the end of the `if` statement.

```js
({ 
    test: () => 
    {
        assert(runPython(`_Node(_code).find_class("Inbox").find_function("list_emails").find_ifs()[0].find_body()[1].is_equivalent("return")`))
    }
})
```

# --seed--

## --seed-contents--

```py
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)

--fcc-editable-region--
    
--fcc-editable-region--

```
