I’ve got some code:
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates
start_point = 10000
#print ('We\'d have {0} beans, {1} jars, and {2} crates.'
.format(secret_formula(start_point)))
print ('We\'d have %d beans, %d jars, and %d crates.'
% secret_formula(start_point))
My question is regarding the two last statements. The one that is commented out does not work (returns an index out of range error), but the other one does. Why is that? And how can I make the commented out statement work?
Thanks in advance 🙂
Lars
The commented out line should be
Notice the
*beforesecret_formula(...)— it tells Python to unpack the result when passing the values toformat().