Write a program that keeps accepting the age of employees in a while loop. If the age entered is negative or above 57, then the loop should stop executing. The program should also print the number of employees who are in the age group 25 to 35.
Answers
Code:
Explanation:
We create a list to store the ages of the employees that are going to be retrieved using the function through the loop. We use conditional statements to check if the age is negative or above 57. If they do not fulfil those conditions, they're added to the list earlier created for the same through the method. We then assign a variable to store the count of the number of employees between the ages 25 and 35. A loop is initiated to traverse through the elements in the list and get the number of employees, again through a conditional statement checking if they're in that age group or not. The final output is then displayed in an appropriate statement.
We create a list to store the ages of the employees that are going to be retrieved using the input() function through the while loop. We use conditional statements to check if the age is negative or above 57. If they do not fulfil those conditions, they're added to the list earlier created for the same through the append() method. We then assign a variable to store the count of the number of employees between the ages 25 and 35. A for loop is initiated to traverse through the elements in the list and get the number of employees, again through a conditional statement checking if they're in that age group or not. The final output is then displayed in an appropriate print() statement.