Two employees are up for the Employee of the Year award. Pick the more productive one and compute their 15% bonus.
You start with:
name1 = "John Doe"
productivity1 = 83
salary1 = 135000
name2 = "Mary Jane"
productivity2 = 133
salary2 = 335000
Build:
Mary Jane Bonus: $50250
Rules:
- The winner is whichever employee has the higher productivity.
- If both have the same productivity, employee 1 (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
if/else to pick the winner. Store both their name and their salary (winner_name, winner_salary) in every branch, so the bonus formula stays simple. A tie goes to employee 1, so compare with >=.
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
if productivity1 >= productivity2:
winner_name = name1
winner_salary = salary1
else:
winner_name = name2
winner_salary = salary2
bonus = winner_salary * 15 // 100
print(winner_name)
print("Bonus: $" + str(bonus))
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
