|
1 |
| - |
2 |
| - |
| 1 | +""" |
| 2 | +11. Male and Female Percentages |
| 3 | +Write a program that asks the user for the number of males and the number of |
| 4 | +females registered in a class. |
| 5 | +The program should display the percentage of males and females in the class. |
| 6 | +Hint: Suppose there are 8 males and 12 females in a class. |
| 7 | +There are 20 students in the class. |
| 8 | +The percentage of males can be calculated as 8 / 20 = 0.4, or 40%. |
| 9 | +The percentage of females can be calculated as 12 / 20 = 0.6, or 60%. |
| 10 | +Reference: |
| 11 | +(1) Starting out with Python, Third Edition, Tony Gaddis Chapter 2 |
| 12 | +(2) https://youtu.be/2M1HVL6nbAY |
| 13 | +""" |
| 14 | +# Get User Input(the number of males and females registered int Class) |
| 15 | +# Convert User input to int |
| 16 | +females = int(input("Please Enter the number of females int Class : ")) |
| 17 | +males = int(input("Please Enter the number of males int Class : ")) |
| 18 | +# Calculate the percentage of males and females |
| 19 | +total_student = males + females |
| 20 | +# first method |
| 21 | +#males_percentage = (males / total_student) * 100 |
| 22 | +#females_percentage = (females / total_student) * 100 |
| 23 | +# second method |
| 24 | +males_percentage = males / total_student |
| 25 | +females_percentage = females / total_student |
| 26 | +# display the percentage |
| 27 | +# first method method |
| 28 | +#print("The females percentage is "+ str(females_percentage) + " %") |
| 29 | +#print("The males percentage is "+ str(males_percentage) + " %") |
| 30 | +# second method |
| 31 | +print("There are " + str(total_student) + " students in the Class " + \ |
| 32 | + format(males_percentage, ".0%") + " of them are males and " + \ |
| 33 | + format(females_percentage, ".0%") + " of them are females") |
0 commit comments