Split coins into combinations of different denominations I have 3 types of coins: Gold, Silver, Copper.
1 silver = 100 copper.
1 gold = 100 silver.  

My input is always in coppers, and I want to be able to make it a bit more readable. So far my code is:  

def api_wallet_translate_gold(value):
    """Translate a value into string of money"""
    if value &gt;= 10000:  # Gold
        return ("{0} gold, {1} silver and {2} copper."
                .format(str(value)[:-4], str(value)[-4:-2], str(value)[-2:]))
    elif value &gt;= 100:  # Silver
        return "{0} silver and {1} copper.".format(str(value)[-4:-2], str(value)[-2:])
    else:  # Copper
        return "{0} copper.".format(str(value)[-2:])


It works, but I am wondering how could it be improved. I think there was a way to format it like {xx:2:2} or something but I can't remember how to do it.  

Note: We never know how many gold digits we have, it could be 999999 to 1
It may less fragile if you deal with the numbers directly rather than converting to strings. It will also be cleaner code.

You could start with your values in a list sorted highest to lowest. Then in your function you can find the next-largest value and remained with divmod(). After than it's a matter of deciding how you want to format the resulting dict:

coins = [
    ("gold",  100 * 100),
    ("silver", 100), 
    ("copper", 1)
]

def translate_coins(value, coins):
    res = {}
    for coin, v in coins:
        res[coin], value = divmod(value, v)
    return res 

translate_coins(1013323, coins)


Result:  

{'gold': 101, 'silver': 33, 'copper': 23}