Imagine that you have a list of the genders (as single characters) of all the students in your class, in order of their last name. The list will look something like “MFFMMMFFMFMMFFFM” where M is male and F is female. Write a function (below) percentageGenders(string) to accept a string that represents the genders. You are to count all of the M’s and F’s in the string and print out the ratio (as a decimal) of the each gender. For example, if the input string were “MFFF,” then the function should print something like, “There are 0.25 males, 0.75 females.” (Hint: Better multiply something by 1.0 to make sure that you get floats not integers.)

What will be an ideal response?


```
def percentageGenders(string):
mCount = string.count("M")
fCount = string.count("F")
total = 1.0*(mCount+fCount)
mPercentage = (mCount/total)
fPercentage = (fCount/total)
print("There are "+String(mPercentage)+" males, "+String(fPercentage)+ " females.")
```

Computer Science & Information Technology

You might also like to view...

Microsoft Excel is the component of the Microsoft Office suite best suited for working with large collections of data.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Creating and using a structure requires that the structure be declared and that values be assigned to the individual structure elements.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

If the Client Number field in a record always should display the two characters in the client number in uppercase, then the correct format for this field is ____.

A. < B. & C. % D. >

Computer Science & Information Technology

In many cases, GIF compression has no noticeable effect on an image.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology