Question

Hi could you explain why my code is not working for b = a + a...

Hi could you explain why my code is not working for b = a + a + a (it's a review question)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

__add__ method must return a new Dist Object to make it work

media%2Fcb8%2Fcb8de3bc-8f26-478b-833e-43

OUTPUT:

media%2F173%2F173afe75-d6e9-41ce-8add-d8

CODE :

class Dist:
def __init__(self,miles=0.0):
self.m = miles

def __repr__(self):
result = round(self.m,1)
return str(result)+'miles'

def addKilo(self):
self.m+=0.62

def __add__(self,other):
total = self.m + other.m
return Dist(total)

  

Add a comment
Know the answer?
Add Answer to:
Hi could you explain why my code is not working for b = a + a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT