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

A(n) ________ is placed at the beginning of a report and includes information such as the student's name and class

A) table of contents B) index C) reference D) cover page

Computer Science & Information Technology

Which of the following technologies is used on the backbone of an ISDN?

A. VDSL B. SDSL C. OC3 D. ATM

Computer Science & Information Technology