Convert dollars to real with Python

Asked

Viewed 3,993 times

-5

Create a program that asks for the amount of US$ and the fee and displays the amount of R$.

dolar = float(input("Informe a quantidade de dólar para conversão: US$ "))
contaçao = float(input ("Informe o valor da cotação do dólar: R$ "))
conversao = float(input(("A quantidade de dólar convertido em real é: R$ ",conversao))
print (dolar*contacao)                                             

I need to do it in Python.

  • what’s going wrong here

  • What was the error message? What did you understand when you read such a message?

  • 1

    How about using a standardized nomenclature? contacao and contaçao are distinct words. You should use only one name to refer to the dollar’s quotation value

  • What is your intention in the line where you read the variable conversao? I found it confusing you use a read command to write the supposed response of converting dollars into real

1 answer

0

Rewriting your code according to a viable logic would look like this. The dolar U$ would be the current value multiplied by the quotation in R$. Basically this would be attributed to conversao. Behold:

dolar = float(input("Informe a quantidade de dólar para conversão: US$ "))
cotacao = float(input ("Informe o valor da cotação do dólar: R$ "))
conversao = dolar*cotacao
print('A quantidade de dólar convertido em real é: R$',conversao)

To limit the number of decimals, for example 3, just use "%.3f" % valor. Take an example:

print('A quantidade de dólar convertido em real é: R$',("%.3f" % conversao))

Behold running here on repl.it.

Browser other questions tagged

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