Python Practice › If-Else Programs › Program 50
Bonus eligibility
Write a Python program that gives a 10% bonus to employees who have served more than 4 years.
Input
(5 years, salary 60000), (3 years, salary 45000)
Output
5 years: eligible, bonus = 6000.0 3 years: not eligible for a bonus
Approach
- Compare years with 4; calculate 10% of the salary when eligible.
Solution
for years, salary in [(5, 60000), (3, 45000)]: if years > 4: bonus = salary * 10 / 100 print(f"{years} years: eligible, bonus = {bonus}") else: print(f"{years} years: not eligible for a bonus")Output
5 years: eligible, bonus = 6000.0 3 years: not eligible for a bonus
Line by line
Line 3
10% of the salary.
Learn the concept
New to this topic? Read the lesson, then come back.