You might find this a useful resource in general for string formatting: https://pyformat.info/ - this should have the information you’ll need, and more, to change that str(total) into more precisely what you want
In general though, if you’re dealing with values that must be represented exactly, like money, then you shouldn’t be using floats to represent them
a common trick with currencies that have cents and pence etc is to track all values in integer numbers of pence rather than pounds, or cents rather than dollars
Alternatively there are libraries including decimal that can deal with this more robustly
I should probably point out for completeness that there’s a built in function, round, that can actually round the number if you want to use the rounded number for other things
The .write method expects, as the message says, a character buffer, which is not interchangeable with numbers. If you want to write the string representation of a number you need to convert it to bytes. The answer to that part is a little less obvious, but converting to a string then encoding it to bytes should do it:
This works perfectly. I’m only just starting to learn Python so some of the explanation is a bit beyond my understanding right now. I’m only just getting to grips with simple loops and lists - working from a book on Python.