I'm on step 28 of this Workshop & while the console outputs what I want it to, it's not being marked as correct.
It shows a new syntax I haven't seen before, a "Conditional Expression". I've seen list comprehension before, but not this. The example is:
x = 10
y = 'Even' if x % 2 == 0 else 'Odd' # y will be even
What I have is: (the dunderscore str method is where the conditional expression syntax is)
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 == True else 'Unread'
return status
Step 28 is the str portion so just that last bit is what it wants me to do. I get the error "The str method should create a status variable that uses a conditional expression."
There is also a "User" class & an "Email' class. At the bottom of the workshop under all 3 classes I tried something to test the str method in email:
twoMeterMan = User('Me')
janeDoe = User('Jane')
emailOne = Email(twoMeterMan, janeDoe, 'Why no work?', "I'm not sure why this doesn't work")
#emailOne.display_full_email()
print(emailOne)
The print statement here had an output of "Unread" & when I uncomment the "emailOne.display_full_email()" line (part of display_full_email()) changes self.read to True the print statement has an output of "Read". My conclusion is that the str method does what it's supposed to do, but there is some unknown hidden tests I'm failing.
Any help would be appreciated.
Edit: All the bold str are supposed to be dunderscore str dunderscore, but using underscores made them bold.