2017-02-09 2 views
-4

프로그램에서 사용자가 원하는 금액을 표시하지 못하는 문제가 있습니다. 또한 어떻게 숫자를 소수점 3 자리로 반올림합니까, 어떤 아이디어입니까?통화 변환기

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 
+0

이 반올림 도움이 http://stackoverflow.com/questions/455612/limiting-floats-to-two-decimal-points – spijs

+4

할 **하지 * * 코드의 포스트 사진, 질문 코드에 * 서식있는 텍스트 *로 게시하십시오. –

+0

"사용자가 원하는 양만큼 프로그램을 변환하지 못하는 문제가 있습니다."- 무엇이 문제입니까? –

답변

0

파이썬은 당신이 원하는 자릿수를 lets you specifyround() 기능을 포함하고 있습니다. 따라서 round(x, 3)을 사용하면 최대 3 자리까지 반올림을 수행 할 수 있습니다.

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

업데이트

이 방법으로 코드를 업데이트 할 수 있습니다.

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)) 

그것은 출력 :

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 
+0

코드에서 정확히 구현할 수있는 부분을 알고 있습니까? –

관련 문제