70.9k views
3 votes
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.

User Fofole
by
6.9k points

1 Answer

3 votes

Answer:

males_num=int(input("Enter the number of males\\"))#taking input of the males_num

female_num=int(input("Enter the number of females\\"))#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%

Step-by-step 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.

User Glocore
by
6.6k points