Computer Science

Write a program to accept the age of n employees and count the number of persons in the following age group:

(i)    26 - 35
(ii)   36 - 45
(iii)  46 - 55

Python

Python Control Flow

20 Likes

Answer

n = int(input("Enter the value of n: "))
g1 = g2 = g3 = 0

for i in range(1, n + 1) :
    age = int(input("Enter employee age: "))
    #We have used chained comparison operators
    if 26 <= age <= 35 :
        g1 += 1
    elif 36 <= age <= 45 :
        g2 += 1
    elif 46 <= age <= 55 :
        g3 += 1

print("Employees in age group 26 - 35: ", g1)
print("Employees in age group 36 - 45: ", g2)
print("Employees in age group 46 - 55: ", g3)

Output

Enter the value of n: 10
Enter employee age: 45
Enter employee age: 53
Enter employee age: 28
Enter employee age: 32
Enter employee age: 34
Enter employee age: 49
Enter employee age: 30
Enter employee age: 38
Enter employee age: 33
Enter employee age: 53
Employees in age group 26 - 35:  5
Employees in age group 36 - 45:  2
Employees in age group 46 - 55:  3

Answered By

4 Likes


Related Questions