Would anybody mind breaking down the above line? I understand these parts:
outputFile.write: writes text into a .txt document named earlier
... .2f\n"
adds 2 decimal points to the end of the float number that’s outputted
(“Total:”, total) outputs the word Total plus the total amount as determined by the equation above.
The part I’m really trying to understand is:
%-20s%10
I know what this does, but don’t understand how the wording works. I understand that this is formatting but exactly how does this format? Is it twenty spaces after the last letter in the first part? etc. etc.
The first one ends with an “s”, so it accepts any value and treats it as
a string. The 20 is the width, and the dash - says to align it at the
left, filling the rest of the width with spaces.
The second code ends with an “f”, so it accepts only floats or numbers
that can be converted to float. The total width is 10 and there are two
decimal places shown, as zero if necessary.