Saving outputs as record in class & update if same product name given as input python

use these codes under def init():

self.last=""
self.finalamount=0

and use this get_value():

def get_value(self):
    if self.last == self.name:
        self.finalamount += self.market_price * self.quantity
    else:
        self.finalamount = self.market_price * self.quantity
        
    self.last=self.name
    return self.finalamount

or you can create a list of last_names for compare with after names

fullcode:

class salesperson:
    
    def __init__(self, name):
        self.name=name
        self.market_price=0
        self.quantity=0
        self.product_name=0
        
        self.last=""
        self.finalamount=0        
        
    def buy_pro(self, product_name, market_price, quantity):
        self.product_name = product_name
        self.market_price=market_price
        self.quantity=quantity
        
        self.a= ({self.product_name: [self.market_price, self.quantity]})
    
    def get_value(self):
        if self.last == self.name:
            self.finalamount += self.market_price * self.quantity
        else:
            self.finalamount = self.market_price * self.quantity
            
        self.last=self.name
        return self.finalamount    
        
    def get_name(self):
        return (self.name)

        

sp_name=salesperson('name')

sp_name.buy_pro('mobile',30,20)
print(sp_name.get_value())

sp_name.buy_pro('mobile',10,2)
print(sp_name.get_value())

in method buy_pro the line which states self.quantity=quantity should be self.quantity += quantity This will update the self.quantity value with the current order quatity