Ononto
Ononto

Reputation: 5

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!

Upvotes: 0

Views: 71

Answers (1)

rchome
rchome

Reputation: 2723

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.

Upvotes: 1

Related Questions