At My Fingertips

Rapid Playground

Documentation

Building a Tower

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.

A Tower with Premade Pieces

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

Loading...

🎉 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

A Tower with Your Own Pieces

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

Loading...
Code is messed up?Always remember that if you edit the cell and you're stuck you can reset it to the original state by clicking this symbol reset symbol on the top right of the page!

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

Logo of PyTamaro

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI

Privacy PolicyPlatform Version 320e1c5 (Thu, 16 May 2024 14:11:39 GMT)