renix1

regra de três, python 3.x

Nov 26th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. # Fazer um algoritmo (simples) de regra de três simples
  2. def main():
  3.     # Primeiro pergunta os números
  4.     n_1 = float(input('Digite o n = '))
  5.     n_2 = float(input('Digite o n = '))
  6.     n_3 = input('Digite o n = ')
  7.     n_4 = input('Digite o n = ')
  8.     if n_3 != 'x':
  9.         n_3 = float(n_3)
  10.     else:
  11.         n_4 = float(n_4)
  12.     # Resolve a conta multiplicando e divindindo
  13.     if type(n_3) == int or type(n_3) == float:
  14.         x = str(n_1)+'x'
  15.         print('passo 1:', x)
  16.         t1 = n_3 * n_2
  17.         print('passo 2:', t1)
  18.         y = float(x.replace('x', ''))
  19.         print('passo 3:', y)
  20.         t2 = t1 / y
  21.         print('resultado final:', t2)
  22.     elif type(n_4) == int or type(n_4) == float:
  23.         x = str(n_2)+'x'
  24.         print('passo 1:', x)
  25.         t1 = n_4 * n_1
  26.         print('passo 2:', t1)
  27.         y = float(x.replace('x', ''))
  28.         print('passo 3:', y)
  29.         t2 = t1 / y
  30.         print('resultado final:', t2)
  31.  
  32. if __name__ == "__main__":
  33.     while True:
  34.         main()
Advertisement
Add Comment
Please, Sign In to add comment