Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

New to programming tried writing a code but it is giving output as none. please help me.

+1 vote
asked Feb 28, 2020 by anonymous
class Shop:
  def __init__(self,name,item_no,price,discount):
    self.name=name
    self.item_no=item_no
    self.price=float(price)
    
  def discount(self,discount_rate,discount_price):
    
    self.discount_rate=float(0.15)
    
    self.discount_price=float(self.price*self.discount_rate/100)-self.price

item1 = Shop('bag','9988','800','0.15')
print(item1.discount("",""))

1 Answer

0 votes
answered Feb 28, 2020 by Ponslin Jash J S
 
Best answer
return self.discount_price, self.discount_rate

Actually when you wanna get result you wanna return the values. so use given above code after

self.discount_price=float(self.price*self.discount_rate/100)-self.price

your full updated code is below:

class Shop:
  def __init__(self,name,item_no,price,discount):
    self.name=name
    self.item_no=item_no
    self.price=float(price)
    
  def discount(self,discount_rate,discount_price):
    
    self.discount_rate=float(0.15)
    
    self.discount_price=float(self.price*self.discount_rate/100)-self.price
    return self.discount_price, self.discount_rate

item1 = Shop('bag','9988','800','0.15')
print(item1.discount("",""))
commented Feb 28, 2020 by anonymous
Thank you so much.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...