программа игнорит ветку elif и лепит все в if

def calc_pro():
    while True:
        try:

            a = float(input('first number: '))
            operation = input('+ - * / tg ctg cos sin: ')
            b = float(input('second number: '))
            round_to = int(input('round to item after coma: '))
            operations = {

                '+': round(a + b, round_to),
                '-': round(a - b, round_to),
                '*': round(a * b, round_to),
                '/': round(a / b, round_to),
                'tg': round(math.tan(a), round_to),
                'cos': round(math.cos(a), round_to),
                'sin': round(math.sin(a), round_to),
                'ctg': round(math.cos(a) / math.sin(a), round_to),
            }

            if operation == '+' or '-' or '*' or '/':
                print('{} {} {} = {}'.format(a, operation, b, operations[operation]))
            elif operation == 'tg' or 'ctg' or 'cos' or 'sin':
                print('{} {}  = {}'.format(operation, a, operations[operation]))

Ответы (2 шт):

Автор решения: Igor
    if operation == '+' or operation == '-' or operation == '*' or operation == '/':
        print('{} {} {} = {}'.format(a, operation, b, operations[operation]))
    elif operation == 'tg' or operation == 'ctg' or operation == 'cos' or operation == 'sin':
        print('{} {}  = {}'.format(operation, a, operations[operation]))

    if operation in ['+', '-', '*', '/']:
        print('{} {} {} = {}'.format(a, operation, b, operations[operation]))
    elif operation in ['tg', 'ctg', 'cos', 'sin']:
        print('{} {}  = {}'.format(operation, a, operations[operation]))
→ Ссылка
Автор решения: eri

Такую конструкцию удобно записать таким образом

if operation in [ '+',  '-', '*', '/'] : 
→ Ссылка