What is the difference between "/" and "%" in python?

Asked

Viewed 75 times

-1

x1 = int(input())
v1 = int(input())
x2 = int(input())
v2 = int(input())

if x1 == x2 and v1 == v2:
  print('SIM')

elif (x1 == x2) and (v1 != v2):
  print('NÃO')

elif (x1 - x2) % (v2 - v1) == 0:
  if (x1 - x2) / (v2 - v1) > 0:
    print('SIM')
  else: print('NAO')

else: print('NAO')

I made that code and I realized that the % and the / totally change the result. What is the difference between them?

  • 3

    % take the rest of the division / normal division operator in some cases(python 2.7) takes only the entire part of the division

1 answer

3


Python has some arithmetic operators, these are:

+   Adição
-   Subtração
*   Multiplicação
/   Divisão 
//  Divisão Inteira
%   Módulo 
**  Exponenciação

Each operator has its function and must be used to achieve a certain purpose. By using the divisão (/) you will be getting the result of the division between two values, already the operator módulo (%), within an operation, return the rest of the division between two values.

Ex:

5/2 = 2.5

5%2 = 1

Browser other questions tagged

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