Doubt about if, Elif and Else

Asked

Viewed 16 times

0

Good morning/late/evening

I started to venture into the recent python and was making a code for a simple calculator exercise.

print('Calculadora simples')


def calculadora():
    x1 = int(input('Digite o primeiro digito: '))
    x = input('Agora digite a natureza da operação: ')
    x2 = int(input('Digite o segundo digito: '))

    if x == '+':
        x3 = x1 + x2
        print('Seu resultado foi: ',x3)
        sair = str(input('Fazer de novo? (S/N)'))

        if sair == 'N' or 'n': #AQUI O ERRO
            print('Saindo...')

        elif sair == 'S' or 's':
           return calculadora()

        else:
            calculadora()


calculadora()

In the if part inside if in sum, when I run it ignores Elif, and only executes if in the beginning.

  • You cannot compare 2 things in one shot. Explain the comparison: if (sair=='N') or (sair =='n').

  • Thanks friend, I have just started to study the language, hence these mistakes of beginner.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.