

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 9
click for more info
Not enough gems
Cost: 6 gems
1: Inheritance
incomplete
2: When to Inherit
incomplete
3: Inheritance Hierarchy
incomplete
4: Inheritance Quiz
incomplete
5: Multiple Children
incomplete
6: Adding a Wizard
incomplete
7: Wide Not Deep
incomplete
8: Dragons
incomplete
9: Dragons Fight
incomplete
10: Inheritance Practice
incomplete
11: Inheritance Practice
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
We've created a lot of classes in this course, now let's write some code that uses them. Let's have ourselves a little dragon fight.
Complete the bottom half of the main() -> None function using two for-loops:
Pass in the dragons in the same order as the original list, excluding the current dragon. For example, when Blue Dragon breathes fire, it should check to breathe fire on the other dragons in this order:
When you describe the dragons, your output should look like this:
Green Dragon is at 0/0
Red Dragon is at 2/2
Blue Dragon is at 4/3
Black Dragon is at 5/-1
The output of the first dragon breathing fire should look like this:
====================================
Green Dragon breathes fire at 3/3 with range 1
------------------------------------
Red Dragon is hit by the fire
Blue Dragon is hit by the fire
====================================
Red Dragon breathes fire at 3/3 with range 2
------------------------------------
To get a new copy of a list, use the copy() method. If you just do new_list = old_list, your new variable will just be a reference to the original list... which is not what we want.
nums: list[int] = [4, 3, 2, 1]
nums_copy: list[int] = nums.copy()
# nums_copy is [4, 3, 2, 1]
fruits: list[str] = ["apple", "banana", "cherry", "kiwi"]
del fruits[1]
# fruits is ["apple", "cherry", "kiwi"]