""" Intro to OOP Finn Aakre Haugen, finn@techteach.no 2025 05 13 """ #%% Class def class Inventory: # Class constructor: def __init__(self, n_init): # Definition of attribute of name x: self.n = n_init # Def of method of name accum: def accum(self, u): self.n += u return self.n #%% Model settings n_init = 10 # Initial contents of inventory #%% Instantiation of object named inventory_1 of class named Inventory inventory_1 = Inventory(n_init) #%% Program part where the inventory_1 object is used for k in range(2): input = 1 contents_meth = inventory_1.accum(input) print(f'Contents from method inventory_1.accum: {contents_meth}') contents_att = inventory_1.n print(f'Contents as attribute inventory_1.n: {contents_att}')