0

why this program is showing error?

class book: def __init__(self,a,b,c,d,e): self.title=a self.author=b self.publisher=c self.price=d self.author_royality=e def showinfo(self): print('title:', self.title) print('author:', self.author) print('publisher:', self.publisher) print('price:', self.price) print('author_royality:', self.author_royality)

26th Jun 2019, 9:21 AM
yash gupta
yash gupta - avatar
6 Antworten
+ 4
Doesn't really match your other question where it says "Provide getter and setter properties for all variables. Also define a method royalty() to calculate royalty amount author can expect to receive the following royalties (...)" A getter method is defined like this: @property def price(self): return self._price A setter method is defined like this: @price.setter def price(self, price): self._price = price For the royalty class method, I'd make a static method as I think the method is the same for all books and you want to be able to call the method without referencing a specific instance of the class: @staticmethod def royalties(retail_price, copies_sold): # calculate royalties here return royalties
26th Jun 2019, 10:42 AM
Anna
Anna - avatar
+ 4
You need to define getters and setters for all properties
26th Jun 2019, 12:16 PM
Anna
Anna - avatar
+ 2
It won't show any error, everything seems fine. To make books you will need to define a new book and give it the attributes a,b,c,d,e Example: book1 = book("any_title", "any_author", "any_publisher", "any_price", "anyauthor_royality") Then you can say: print(book1.showinfo())
26th Jun 2019, 9:42 AM
Mo Hani
Mo Hani - avatar
+ 1
after making object and calling showinfo method it is showing bound error
26th Jun 2019, 12:06 PM
yash gupta
yash gupta - avatar
+ 1
<bound method book.showinfo of <__main__.book object at 0x03066190>>
26th Jun 2019, 12:11 PM
yash gupta
yash gupta - avatar
0
static method cannot modify the state of object but i also have to change the state of object
26th Jun 2019, 5:07 PM
yash gupta
yash gupta - avatar