Tell us what’s happening:
Hi i can’t get past step 35 even tho the code logic seems to work in other editors. makes me think it’s an issue with the formating. But i can’t figure it out. Has someone some insight?
Thanks a lot
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() # Mark the email as read when it's displayed
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):
# Create and send an email
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):
# Check if the inbox is empty
if not self.emails:
# User Editable Region
print('Inbox is empty.\n')
return
# Convert the 1-based index to 0-based index (for Python list indexing)
actual_index = index - 1
# Step 35: Check if the actual_index is within valid bounds
if actual_index < 0 or actual_index >= len(self.emails):
print("Invalid email number.\n")
return
# Access the email at actual_index and display its full content
email = self.emails[actual_index]
email.display_full_email() # This will display the email content
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0
Challenge Information:
Build an Email Simulator - Step 35