From f56ffb777617993350e893567b92c0493302350e Mon Sep 17 00:00:00 2001 From: Davide Grilli Date: Thu, 9 Apr 2026 19:56:51 +0200 Subject: [PATCH] aggiunge esercizio 36 --- lab36.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lab36.py diff --git a/lab36.py b/lab36.py new file mode 100644 index 0000000..e8484be --- /dev/null +++ b/lab36.py @@ -0,0 +1,32 @@ +class Stack: + def __init__(self): + self.__stack_list = [] + + def push(self, val): + self.__stack_list.append(val) + + def pop(self): + val = self.__stack_list[-1] + del self.__stack_list[-1] + return val + +class CountingStack(Stack): + def __init__(self): + Stack.__init__(self) + self.__j = 0 + + def get_counter(self): + return self.__j + + def pop(self): + self.__j += 1 + return Stack.pop(self) + + +stk = CountingStack() + +for i in range(100): + stk.push(i) + stk.pop() + +print(stk.get_counter()) \ No newline at end of file