#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 29 08:28:32 2026

@author: pjoulaud
"""

import doctest

class Stack:
    def __init__(self):
        self._data = []
    def push(self, v):
        """
        >>> s = Stack()
        >>> s.push(77)
        >>> s.push(88)
        """
        self._data.append(v)
    def pop(self):
        """
        >>> s = Stack()
        >>> s.push(77)
        >>> s.push(88)
        >>> s.pop()
        88
        >>> s.pop()
        77
        """
        if len(self._data)==0:
            raise RuntimeError("Empty Stack error")
        else :
            return self._data.pop()
    def is_empty(self):
        """
        >>> s = Stack()
        >>> s.push(77)
        >>> s.is_empty()
        False
        >>> s.pop()
        77
        >>> s.is_empty()
        True
        """
        if len(self._data)==0:
            return True
        else :
            return False
    def __repr__(self):
        chaine = ""
        for elem in self._data:
            chaine = f"|{elem}|\n" + chaine
        chaine = chaine + "___"
        return chaine

def calcul(p:Stack, ope:str)->float :
    """
    >>> s = Stack()
    >>> s.push(77)
    >>> s.push(88)
    >>> calcul(s, '+')
    |165|
    ___

    """
    n1 = p.pop()
    n2 = p.pop()
    if ope=='+':
        p.push(n1 + n2)
    elif ope=='-':
        p.push(n1 - n2)
    elif ope=='*':
        p.push(n1 * n2)
    elif ope=='/':
        p.push(n1 / n2)
    elif ope=='**':
        p.push(n1 ** n2)
    else :
        raise RuntimeError("L'operande n' est pas correcte")
    return p

def evaluation_lst(l:list)->float:
    >>> evaluation_lst
    >>> calcul(s, '+')
    |165|

doctest.testmod()