Skip to content

Instantly share code, notes, and snippets.

@MichalCab
Last active April 4, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichalCab/3c94130adf9ec0c486dfca8d0f01d794 to your computer and use it in GitHub Desktop.
Save MichalCab/3c94130adf9ec0c486dfca8d0f01d794 to your computer and use it in GitHub Desktop.
Kiwi.com - Python junior dev

Create currency converter

Limitations

No limitations.

  • Python2.7 or 3
  • all modules are allowed

Parameters

  • --amount - amount which we want to convert - float
  • --input_currency - input currency - 3 letters name or currency symbol
  • --output_currency - requested/output currency - 3 letters name or currency symbol

Functionality

  • if output_currency param is missing, convert to all known currencies

Output

  • json with following structure.
{
    "input": { 
        "amount": <float>,
        "currency": <3 letter currency code>
    }
    "output": {
        <3 letter currency code>: <float>
    }
}

Examples

./currency_converter.py --amount 100.0 --input_currency EUR --output_currency CZK
{   
    "input": {
        "amount": 100.0,
        "currency": "EUR"
    },
    "output": {
        "CZK": 2707.36, 
    }
}
./currency_converter.py --amount 0.9 --input_currency ¥ --output_currency AUD
{   
    "input": {
        "amount": 0.9,
        "currency": "CNY"
    },
    "output": {
        "AUD": 0.20, 
    }
}
./currency_converter.py --amount 10.92 --input_currency £ 
{
    "input": {
        "amount": 10.92,
        "currency": "GBP"
    },
    "output": {
        "EUR": 14.95,
        "USD": 17.05,
        "CZK": 404.82,
        .
        .
        .
    }
}
@zlondrej
Copy link

Are you aware that multiple currencies use same symbols?
See World Currency Symbols

How is the program supposed to handle difference between Canadian Dollar and US Dollar ($) or between Japanese Yen and Chinese Yuan (¥) which use same symbol?

There are 24 currencies that use dollar sign as currency symbol so there is need for disambiguation.

I expect that some sort of online currency converter service was used which handles the conversion automatically. I suggest that you give us the link to the service, clearly define rules for disambiguation or drop the currency symbol option completely.

I look forward to your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment