The source of the confusion is what format() does and what the % sign is for in that code. But it doesn't calculate the percentage for you. It simply takes the values you give it as arguments and plugs it into the the part that says %{..}.
The str.format() method is a bit of tough one to explain and to be honest I don't understand it completely myself.
There is an alternative that works perfectly fine for cases like these, but str.format() is better. I suggest you Percentage calculator through this you get more results about How to calculate percentage .
The alternative is to use the string formatting operator. That might sound abit confusing but it sounds similar to the str.format() method because it does the same thing in a less sophisticated and less powerful form.
The way it works is:
>>> "blah blah %s" % "BlaH"
'blah blah BlaH'
>>>
To calculate percentage you first get the ratio by dividing the part by the whole. This is represented as some decimal less than 1. Example, 0.25.
Then multiply the ratio by 100 to express that ratio in the form of a percentage.
So that line should become.
ratio = females / total
print("Females is %0.2f%%" % (ratio * 100))