Computer Science, asked by rashidkalodi1078, 3 days ago

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

Answered by Equestriadash
8

Cod‎e:

\tt l\ =\ list()\\while\ True:\\{\ \ \ \ \ }age\ =\ int(in put("Enter\ the\ age:\ "))\\{\ \ \ \ \ }if\ age\ <\ 0\ or\ age\ >\ 57:\\{\ \ \ \ \ }{\ \ \ \ \ }break\\{\ \ \ \ \ }else:\\{\ \ \ \ \ }{\ \ \ \ \ }l.append(age)\\c\ =\ 0\\for\ i\ in\ l:\\{\ \ \ \ \ }if\ i\ >=\ 25\ and\ i\ <=\ 35:\\{\ \ \ \ \ }{\ \ \ \ \ }c\ =\ c\ +\ 1\\print("There\ are",\ c,\ "employees\ between\ the\ ages\ 25\ and\ 35.")

Explanation:

We create a list to store the ages of the employees that are going to be retrieved using the \tt in put() function through the \tt 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 \tt append() method. We then assign a variable to store the count of the number of employees between the ages 25 and 35. A \tt 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 \tt print() statement.

Answered by ADITYABHAIYT
1

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.

Similar questions