Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove None value from output

So I’m doing an assignment.My task is to create a class that prints out the desired output in the question. My output matches the desired output except the None value. So Why am I getting None in my output after Total price. I see nothing in my code that should print None.
My Code:

class Dolls:
    def __init__(self, name, price):
        self.name = name
        self.price = price

    def detail(self):
        print("Doll :",self.name)
        print("Total Price :",self.price)

    def __gt__(self,other):
        return self.price > other.price
        
    def __add__(self,other):
        self.name=self.name+","+other.name
        self.price=self.price+other.price
        return self

obj_1 = Dolls("Tweety", 2500)
print(obj_1.detail())
if obj_1 > obj_1:
    print("Congratulations! You get the Tweety as a gift!")
else:
    print("Thank you!")
print("=========================")
obj_2 = Dolls("Daffy Duck", 1800)
print(obj_2.detail())
if obj_2 > obj_1:
    print("Congratulations! You get the Tweety as a gift!")
else:
    print("Thank you!")
print("=========================")
if obj_4 > obj_1:
    print("Congratulations! You get the Tweety as a gift!")
else:
    print("Thank you!")
print("=========================")
obj_5 = obj_2 + obj_3
print(obj_5.detail())
if obj_5 > obj_1:
    print("Congratulations! You get the Tweety as a gift!")
else:
    print("Thank you!")

The output:

Doll : Tweety
Total Price : 2500
None
Thank you!
=========================
Doll : Daffy Duck
Total Price : 1800
None
Thank you!
=========================
Doll : Daffy Duck,Bugs Bunny
Total Price : 4800
None
Congratulations! You get the Tweety as a gift!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your detail() function doesn’t return anything, so the return value there is None. Replace the lines like print(obj_1.detail() with obj_1.detail() without the print and it should get rid of the printed None‘s.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading