-4

I have an issue where the program wouldn't display the desired amount of amount the user wanted to convert. Also how do you round the number to 3 decimal places, any ideas?

money = int(input("Enter the amount of money IN GDP you wish to convert :"))

USD = 1.25
EUR = 1.17
RUP = 83.87
PES = 25.68

currency = input("Which currency would you like to convert the money into?")

if currency == "USD":
    print(money) * USD
elif currency == "EUR":
    print(money) * EUR
elif currency == "RUP":
    print(money) * RUP
elif currency == "PES":
    print(money) * PES
  • This should help for rounding http://stackoverflow.com/questions/455612/limiting-floats-to-two-decimal-points – spijs Feb 09 '17 at 20:47
  • 4
    do **not** post pictures of code, post code as *formatted text* in the question itself. – juanpa.arrivillaga Feb 09 '17 at 20:47
  • "I have an issue where the program wouldn't display the desired amount of amount the user wanted to convert" - what is the issue? – Wasi Ahmad Feb 09 '17 at 20:50
  • 1
    I did not downvote you because I assumed this was a first question. Although, I should have but I didn't realize you've been on the site for a couple of months and you still do not post on-topic questions. Instead of whining about being downvoted, though, maybe you should strive *to post according to the guidelines* – juanpa.arrivillaga Feb 09 '17 at 20:51
  • @juanpa.arrivillaga Here is the error code after I state what currency I would lie it to convert to. Traceback (most recent call last): File "C:\Users\Amir\Downloads\CURRENCY CONVERTOR EXT.py", line 11, in print (money) * 1.25 TypeError: unsupported operand type(s) for *: 'NoneType' and 'float' – AmirBreakable Tv Feb 09 '17 at 20:51
  • You should do `print( money * coef )` instead of `print( money ) * coef` – Reaper Feb 09 '17 at 20:51
  • 1
    Please post error tracebacks *in the original question, not in the comments*. – juanpa.arrivillaga Feb 09 '17 at 20:52
  • @Reaper what is coef do I include it or substitute it with the currency – AmirBreakable Tv Feb 09 '17 at 20:53
  • 1
    Do not use floats (or doubles) to represent money. Use Decimal or integer number of cents. – cmd Feb 09 '17 at 20:54
  • @AmirBreakableTv Whatever you were multiplying `money` by. – Reaper Feb 09 '17 at 20:56
  • @Reaper not working tried that – AmirBreakable Tv Feb 09 '17 at 20:59

1 Answers1

0

Python includes the round() function which lets you specify the number of digits you want. So you can use round(x, 3) to do normal rounding up to 3 decimal places.

Example

print(round(5.368757575, 3)) # prints 5.369

Update

You can update your code in this way.

money = int(input("Enter the amount of money IN GDP you wish to convert: "))

USD = 1.25
EUR = 1.17
RUP = 83.87
PES = 25.68

currency = input("Which currency you like to convert the money into?: ")

if currency == "USD":
    print(round(money * USD, 3))
elif currency == "EUR":
    print(round(money * EUR, 3))
elif currency == "RUP":
    print(round(money * RUP, 3))
elif currency == "PES":
    print(round(money * PES, 3))

It outputs:

Enter the amount of money IN GDP you wish to convert: 100
Which currency you like to convert the money into?: USD
125.0

Enter the amount of money IN GDP you wish to convert: 70
Which currency you like to convert the money into?: RUP
5870.9
Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161