How Do You Calculate Ratio Of Females And Males As A Percentage?

3

3 Answers

John  Munos Profile
John Munos answered

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))

Oddman Profile
Oddman answered
To convert any ratio to a percentage, multiply it by 100%.

9/10 = (9/10)*100% = (900/10)% = 90%
Anonymous Profile
Anonymous answered
If you have 20 women and 25 men there are 45 people altogether.

20 = women so 20 divided by 45 = 0.444444444444  = 44.4% or 44% rounded
45

25 = men so 25 divided by 45 = 0.5555555555 = 55.5% or 56% rounded
45

Answer Question

Anonymous