Build an Email Simulator - Step 4

Tell us what’s happening:

I don’t understand why I am getting the message “You should create an email object named email_obj with the specified parameters”. The printout is what is required yet it won’t pass. Could someone help please? Thank you. - Ann

Your code so far

class Email:
    def __init__(self, sender, receiver, subject, body):
        self.sender = sender
        self.receiver = receiver
# User Editable Region
        self.subject = subject
        self.body = body

email_obj = Email(
    sender="alice@example.com",
    receiver="bob@example.com",
    subject="Hello",
    body="Hi Bob!"
)

print(email_obj.sender) 
print(email_obj.subject) 





# 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/150.0.0.0 Safari/537.36 Edg/150.0.0.0

Challenge Information:

Build an Email Simulator - Step 4

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

Since you’re working with a class, do you remember how to create an instance of the class, passing attribute values to it?

You might want to review this theory lecture:
Classes and Objects - How Do Classes Work and How Do They Differ From Objects? | Learn | freeCodeCamp.org

Do I need to do the same thing as I did with the class Email? The answers expected come up on the terminal yet this does not pass. I am confused.

You are using keyword arguments but this exercise seems to require positional arguments.

https://www.pythontutorials.net/blog/how-to-pass-an-input-argument-when-creating-an-instance-of-a-class

Possibly because keyword arguments have not been taught yet, but maybe they should be accepted here.

When you create an instance of a class, you pass in the attribute values expected by the class’s init method.

And that looks something like this: ClassName(attribute_1, attribute_2, ...)

What you’re doing is using Email like you’re calling a function with default parameters.

Does that make sense?

Thank you both for your help! I figured it out and it worked perfectly.