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
24 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
5 Likes
Related Questions
Write Python programs to sum the given sequences:
12 + 32 + 52 + ….. + n2 (Input n)
Write a Python program to sum the sequence:
1 + 1/1! + 1/2! + 1/3! + ….. + 1/n! (Input n)
Write programs to find the sum of the following series:
x - x2/2! + x3/3! - x4/4! + x5/5! - x6/6! (Input x)
Write programs to find the sum of the following series:
x + x2/2 + x3/3 + …… + xn/n (Input x and n both)