A whole team is competing. Use a for loop over the lists to find the most productive employee, then print their 15% bonus.
You start with:
names = ["John Doe", "Mary Jane", "Bob Smith", "Alice Chen", "Carlos Diaz"]
productivities = [83, 133, 97, 150, 120]
salaries = [135000, 335000, 210000, 250000, 180000]
Build:
Alice Chen Bonus: $37500
Rules:
- Index
iin all three lists refers to the same employee. - The winner is whichever employee has the highest productivity. If two 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.
Start with
best_index = 0 and loop over the other indices with for i in range(1, len(names)). Inside the loop, update the best index only when productivities[i] > productivities[best_index]: a strict comparison keeps the first employee on a tie.
Use integer division
// so the bonus stays a whole number: bonus = salaries[best_index] * 15 // 100.
Joining text and a number needs
str(): print("Bonus: $" + str(bonus))
names = ["John Doe", "Mary Jane", "Bob Smith", "Alice Chen", "Carlos Diaz"]
productivities = [83, 133, 97, 150, 120]
salaries = [135000, 335000, 210000, 250000, 180000]
best_index = 0
for i in range(1, len(names)):
if productivities[i] > productivities[best_index]:
best_index = i
bonus = salaries[best_index] * 15 // 100
print(names[best_index])
print("Bonus: $" + str(bonus))
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
