How do I apply a condition to a line that skips the next line? (python beginner)

Asked

Viewed 44 times

0

I’m very beginner in python and I’m making a simple calculator, but I have a question that I can’t find anywhere. I want to make a condition for, if the chosen operation is */ (what I used to symbolize square root), he ignore the next question. exemplifying:

n1 = int(input('Digite o número 1: '))
op = input('Digite a operação: ')
n2 = int(input('Digite o número 2: '))

I want that if I type */ (responding to op) he skip the next order, which would be Digite o número 2: and go straight to calculus

1 answer

1


Simple, Eric. In your case it’s just encapsulating the n2 in a if and test the operation. If the value is not */, that symbolizes its square root, then the line is executed, otherwise it will be skipped:

n1 = int(input('Digite o número 1: '))
op = input('Digite a operação: ')
if op != '*/':
    n2 = int(input('Digite o número 2: '))

Since you are a beginner, maybe here is a brief explanation: the != used in the test of if symbolizes other than in Python

  • 2

    Thank you very much!! It worked great!!!

Browser other questions tagged

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