How to get a correct value using the point?

Asked

Viewed 71 times

-1

preco_casa = float (input("Qual o preço do imóvel?"))
seu_salario = input("Qual o seu salário mensal?:")
anos_a_pagar = input("Quantidade de anos a pagar pelo imóvel:")
valor_prestacao = preco_casa / (anos_a_pagar *12)
print (" O valor da prestação será de R$%.2f" % valor_prestacao)

Erro quando digita

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

1 answer

2

Treating this correctly can take a little work, but a basic solution to a simple example like this would be to remove the point if there is one, something like that:

preco_casa_raw = input("Qual o preço do imóvel?")
preco_casa = float(preco_casa_raw.replace('.', ''))
seu_salario = float(input("Qual o seu salário mensal?:"))
anos_a_pagar = float(input("Quantidade de anos a pagar pelo imóvel:"))
valor_prestacao = preco_casa / (anos_a_pagar * 12)
print (" O valor da prestação será de R$%.2f" % valor_prestacao)

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

You’ll have to do it on everyone who enters numerical values.

  • Thank you!! it worked.

Browser other questions tagged

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