formula to convert grams into kilograms code example Example: grams in kg def kg_to_g(kg): return kg*1000