Build an Email Simulator - Step 43

Tell us what’s happening:

Unfortunately this snipped doesn’t pass the test for the “Received”-line but the console output seems fine:

My output:
…**
From: Bob
To: Alice
Subject: subject**
Received: 2025-11-13 23:43
Body: body

The commented-out versions are also not accepted, but the output is correct.

What’s wrong with my solution?

Thanks in advance, Martin

Your code so far

import datetime

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

    def mark_as_read(self):
        self.read = True


# User Editable Region

    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('Received: ' + self.timestamp.strftime('%Y-%m-%d %H:%M'))
        #print('Received:', self.timestamp.strftime('%Y-%m-%d %H:%M'))         
        #print(f'Received: {self.timestamp:%Y-%m-%d %H:%M}')
        print(f'Body: {self.body}')
        print('------------\n')

# User Editable Region


    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
        self.emails[actual_index].display_full_email()

    def delete_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
        del self.emails[actual_index]
        print('Email deleted.\n')

bob = User("Bob")
alice = User("Alice")
mail = Email(bob, alice, "subject", "body")
mail.display_full_email()

Your browser information:

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

Challenge Information:

Build an Email Simulator - Step 43

Welcome to the forum @martin.s.schneider

Try using an f-string like the other fields.

Happy coding

Hi Teller,

thanks for your fast reply!

I tried these 4 alternatives and the output seems to be the expected, but the test doesn’t pass:

print(‘Received: ’ + self.timestamp.strftime(’%Y-%m-%d %H:%M’))

print(‘Received:’, self.timestamp.strftime(‘%Y-%m-%d %H:%M’))

print(‘Received:’, f’{self.timestamp:%Y-%m-%d %H:%M}')

print(f’Received: {self.timestamp:%Y-%m-%d %H:%M}')

Honestly, I can’t think of anything else right now… What else could I try?

Regards,

Martin

make everything an f string and interpolate the datetime in the string, in the one you do the interpolation you have lost strftime

Had same issue - Tip - One approach:

Build the fstring with “ [double quotes]” and use single quotes inside for strftime format - otherwise unclear to interpreter.

I had about talked myself into using single quotes exclusively for all str instances but in this case with internal str formatting requiring quotes seems better to use double “outside” and ‘single’ quotes internal to str build.