Bonus eligibility

EasyIf-Else Programs · 50 of 64

Write a Python program that gives a 10% bonus to employees who have served more than 4 years.

Advertisement
Input
(5 years, salary 60000), (3 years, salary 45000)
Output
5 years: eligible, bonus = 6000.0
3 years: not eligible for a bonus

Approach

  1. Compare years with 4; calculate 10% of the salary when eligible.

Solution

Python
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.

More if-else programs

← All 64 If-Else Programs

Leave a Comment