Ex26 - tuple index out of range

Hi,

Here is my last unsolved error for this exercise:

Traceback (most recent call last):
File “ex26.py”, line 67, in
print(“We’d have {} beans, {} jars, and {} crates.”.format(formula))
IndexError: tuple index out of range

I don’t understand because if I print “formula” it gives me: (500000.0, 500.0, 5.0)

So if I do this: print(“We’d have {} beans, {} jars, and {} crates.”.format(500000.0, 500.0, 5.0))
It works and it print: We’d have 500000.0 beans, 500.0 jars, and 5.0 crates.

I have search google for this error, not sure understand. It’s related to index …

Can someone help me?

Thanks,

villenjf
your line:

print(“We’d have {} beans, {} jars, and {} crates.”.format(formula))

is missing an asterisk ‘*’ it should read

print("We'd have {} beans, {} jars, and {} crates.".format(*formula))

I think the asterisk means inset items in the order they appear in formula.
json

Hi Jason,

Thank you very very much for the answer, I had this stuck in the back of my head since then. I tested your solution, and it work. I thought this definition of the asterisk use like this was related to a function thing.

def print_two(*args):
arg1, arg2 = args
print(f"arg1: {arg1}, arg2: {arg2}")

My mistake, it’s more related to list and format I beleive now.

Best regards,