At My Fingertips
Rapid Playground
Lists are something you are probably familiar with from daily life; a shopping list, a list of guests to a party, etc...
We often arrange objects, or people, in a list. The same concept exists when talking about programming.
📖 In Python we write lists in the following format:
[element_1, element_2, element_3, element_4]
📖 You can add as many elements as you want to a list, you can even have an empty list! This is just an example with 4 elements.
The following code example creates a list containing 3 premade castle components and assigns the name tower_pieces
to it using the =
symbol.
tower_pieces = [magical_battlement, magical_wall, icy_wall]
You may be wondering why we are introducing the concept of lists. It's because we have an awesome function that allows you to place all the elements in a given list one above the other, called above_list
.
We can use it to build towers! Towers let you see far to spot the apporaching Swiss!
💡 Hint: replace ...
with icy_wall
🎉 Well done!
📖 Notice that the first element of the list passed to above_list
goes on the top of the tower, and the last element of the list goes on the bottom.
Let's do it one more time
💡 Remember that the roof
function takes one argument: the color of the roof.
💡 Remember that the wall
function takes three arguments: the color, a wall border, and a wall property.
⚠️ Notice that after creating your list, we place all the elements above each other using above_list
, assign the name tower
to the result, and we output tower
using show_graphic
!
If there is no error, you should see your tower in the output.
🚀 Good job! You are ready to continue!
This activity has been created by LuCE Didactics Innovation Team and is licensed under CC BY-SA 4.0.
Building a Tower
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version 087deb5 (Thu, 13 Mar 2025 15:17:46 GMT)