Ask Question
10 November, 07:37

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.

+4
Answers (1)
  1. 10 November, 07:43
    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers