 Computers and Technology
14 July, 21:36

# Write a program that asks the user for the number of males and the number of females registered in a class using two separate inputs ("Enter number of males:", "Enter number of females:"). The program should display the percentage of males and females (round to the nearest whole number) in the following format:Percent males: 35%Percent females: 65%Use string formatting.

+3
1. 14 July, 22:23
0
males_num=int (input ("Enter the number of males/n")) #taking input of the males_num

female_num=int (input ("Enter the number of females/n")) #taking input of the female_num

percentage_male = (males_num / (males_num+female_num)) * 100#calculating the percentage.

print ("Percent males: "+str (percentage_male) + "%") #printing the male percentage.

print ("Percent females: "+str (100-percentage_male) + "%") #printing the female percentage.

Enter the number of males

21

Enter the number of females

45

Percent males: 31.818181818181817%

Percent females: 68.18181818181819%

Explanation:

The above written code is in python. I have first taken input of the number of males then input of the number of males after that calculating the male percentage in the class. Then calculating the percentage of female students by subtracting the male percentage form 100 that's how we will get the respective percentages then printing the percentages.