Oct-03-2019, 06:56 AM
I am working with the following code and I am trying to understand what the purpose of the asterisk within the ".format(*formula)" operation on the last line of the script is. When I remove the asterisk, running the script gives the following error: "IndexError: tuple index out of range"
Can someone help me understand what the asterisk is? And what it is doing to allow the results of the function to print within the formatted string on the last line? Thanks for reading
Can someone help me understand what the asterisk is? And what it is doing to allow the results of the function to print within the formatted string on the last line? Thanks for reading

def secret_formula(started): jelly_beans = started * 500 jars = jelly_beans / 1000 crates = jars / 100 return jelly_beans, jars, crates start_point = 10000 beans, jars, crates = secret_formula(start_point) #remember that this is another way to format a string print("With a starting point of: {}".format(start_point)) #it's just like with an f"" string print(f"We'd have {beans} beans, {jars} jars, and {crates} crates." ) start_point = start_point / 10 print("We can also do that this way:") formula = secret_formula(start_point) #this is an easier way to apply a list to a format string print("We'd have {} beans, {} jars, and {} crates.".format(*formula))