I have the following repetitive simple code repeated several times that I would like to make a function for:
for i in range(10):
id = "some id string looked up in dict"
val = 63.4568900932840928 # some floating point number in dict corresponding to "id"
tabStr += '%-15s = %6.1f\n' % (id,val)
I want to be able to call this function: def printStr(precision)
Where it preforms the code above and returns tabStr
with val
to precision
decimal points.
For example: printStr(3)
would return 63.457
for val
in tabStr
.
Any ideas how to accomplish this kind of functionality?