Start learning free

LESSON 94 OF 410 · CONDITIONAL STATEMENTS - CHALLENGES

Employee of the Year V3 - Project in Python

Practice

Three employees compete for the award. Use a chained if / elif / else to pick the most productive one and print their 15% bonus.

You start with:

name1 = "John Doe"
productivity1 = 83
salary1 = 135000
name2 = "Mary Jane"
productivity2 = 133
salary2 = 335000
name3 = "Bob Smith"
productivity3 = 97
salary3 = 210000

Build:

Mary Jane
Bonus: $50250

Rules:

  • The winner is whichever of the three employees has the highest productivity.
  • If two or more employees share the highest productivity, the one listed first wins.
  • The winner's bonus is 15% of their salary, rounded down to a whole number.
  • Print the winner's name on the first line, then "Bonus: $<amount>" on the second.

Use an if/elif/else chain to pick the winner. Store both their name and their salary (winner_name, winner_salary) in every branch, so the bonus formula stays simple. Employee 1 wins when its productivity is at least that of both others; if not, employee 2 wins when it is at least employee 3's; otherwise employee 3 wins.

Use integer division // so the bonus stays a whole number: bonus = winner_salary * 15 // 100.

Joining text and a number needs str(): print("Bonus: $" + str(bonus))

name1 = "John Doe"
productivity1 = 83
salary1 = 135000
name2 = "Mary Jane"
productivity2 = 133
salary2 = 335000
name3 = "Bob Smith"
productivity3 = 97
salary3 = 210000

if productivity1 >= productivity2 and productivity1 >= productivity3:
    winner_name = name1
    winner_salary = salary1
elif productivity2 >= productivity3:
    winner_name = name2
    winner_salary = salary2
else:
    winner_name = name3
    winner_salary = salary3
bonus = winner_salary * 15 // 100
print(winner_name)
print("Bonus: $" + str(bonus))

STEP 1 OF 9
    Ctrl + Enter to check

    Employee Of The Year V3 in Python

    Keep going with PythonAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free