나는 이렇게 학습한다/Algorithm & SQL

1021. USD => CNY

daco2020 2022. 10. 21. 22:55
반응형

Create a function that converts US dollars (USD) to Chinese Yuan (CNY) . The input is the amount of USD as an integer, and the output should be a string that states the amount of Yuan followed by 'Chinese Yuan'

Examples (Input -> Output)

15  -> '101.25 Chinese Yuan'
465 -> '3138.75 Chinese Yuan'

The conversion rate you should use is 6.75 CNY for every 1 USD. All numbers should be represented as a string with 2 decimal places. (e.g. "21.00" NOT "21.0" or "21")



Solution:

def usdcny(usd: int, exc: int = 6.75):
    return f"{usd*exc:.2f} Chinese Yuan"


반응형