class Book:
prices={"A":45,"B":56,"C":67,"D":78,"E":90.1}
shipping=5
def __init__(self,book_name,num,free_ship):#书名,数量,免运费金额
self.book_name=book_name
self.num=num
self.free_ship=free_ship
def totals(self):
price=Book.prices.get(self.book_name)
if price :
t=price*self.num
return(t+Book.shipping) if t<self.free_ship else t
return "no this book"
book_a=Book("A",2,100)
a_total=book_a.totals()
print(a_total)
输出:95