

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Welcome to Object-Oriented Programming
incomplete
2: Clean Code
incomplete
3: DRY Code
incomplete
4: DRY Review
incomplete
This lesson's interactive features are locked, please to keep using them
One of the most famous rules for maintainable code is "Don't Repeat Yourself" (DRY): avoid writing the same logic twice! Duplicate code causes problems:
The fight_soldiers function currently repeats its DPS (damage-per-second) calculation. These two lines are almost identical, but the second one has a bug:
soldier_one_dps = soldier_one["damage"] * soldier_one["attacks_per_second"]
soldier_two_dps = soldier_two["damage"] - soldier_two["attacks_per_second"]
Replace both calculations with calls to get_soldier_dps, providing the correct soldier as an argument.
You can call the function like this:
soldier_one_dps = get_soldier_dps(soldier_one)
Then do the same thing, but for soldier_two.