We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dragons Fight

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.

Assignment

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:

  1. Green Dragon
  2. Red Dragon
  3. Black Dragon

Example Output

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
------------------------------------

Tips

Copying a List

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]

Delete from a List

fruits: list[str] = ["apple", "banana", "cherry", "kiwi"]
del fruits[1]
# fruits is ["apple", "cherry", "kiwi"]