Hour of Code ® with PyTamaro

Program Your Own Castle
Teacher Notes

You intend to let your class program their own castle? This self-guided one-hour tutorial combines programming and history. It is targeted at students aged 13 and older, who are ready to make their first steps in a text-based programming language.
Photo of Castle

Guidance

These teacher notes provide information on the pedagogy and content (programming and history) of this Hour of Code tutorial. If you would like to go beyond this one-hour tutorial, check out our many free resources on this PyTamaro web site. Many of the resources are used in computer science courses in Swiss high schools.

This Hour of Code was Developed by Students!

Yes! This Hour of Code was developed by informatics students at a small public university in Switzerland.

Agnese
Zamboni
Lead Developer
Davide
Frova
Developer
Giorgia
Lillo
Developer
Jamila
Oubenali
Developer

The content (activities and sequencing, instructions, starter and solution code, and all pre-made graphics, which were programmed, not drawn, by composing geometric primitives with Python/PyTamaro code) was developed by a small team of undergraduate students at the Faculty of Informatics at USI, the Università della Svizzera italiana, in the Italian-speaking part of Switzerland. Funded by a didactics innovation grant, they spent a month in summer 2023 visiting the real Fortezza Bellinzona, building the largest toy castles out there, researching existing Hour Of Code activities, and then developing this activity in Python on top of the PyTamaro Web platform.

Luca
Chiodini
Platform
Igor
Moreno
PL Advice
Joey
Bevilacqua
Engineering
Matthias
Hauswirth
Organization

The PyTamaro Web platform and the compositional PyTamaro graphics library for Python were primarily developed by Luca Chiodini, a PhD student in the Lugano Computing Education research lab at USI. Luca had been teaching Swiss high school teachers who were going to teach Python programming in their future classes. He realized the benefits of a simple, compositional graphics library, so he implemented PyTamaro. To support teachers in their future teaching, he developed the PyTamaro Web platform. This allows students to program Python using PyTamaro directly in the browser, in a notebook-like environment, where instructions and code are interleaved in interactive exercises.

Pedagogy

Here are a few pedagogical tips to help you make the most of an Hour of Code:

  • 💡
    Pair Programming

    This Hour of Code can work particularly well in a pair-programming setting, where two students work together at one computer. In pair programming, the two students in a pair usually take on different roles: the driver is at the keyboard writing code, and the navigator is reviewing each line of code as it is typed in. You may ask students to switch roles between each activity (but note that the first few activities do not require much writing).

  • 💡
    Platforms

    We tested this tutorial on the Firefox, Chrome, Safari, and Edge browsers and on macOS, Windows, iOS, iPadOS, and Android. While it can be used on mobile phones, we recommend devices with larger screens and keyboards.

  • 💡
    Competencies

    Each activity is associated with one or more programming competencies. Whenever a student completes an activity, the competencies they just practiced are added as blue 'badges' to the left sidebar. Encourage your students to click on the badges to read their descriptions. This introduces them to the terminology of programming concepts. You can find a matrix aligning activities and competencies below.

  • 💡
    Misconceptions

    Your students may have various misconceptions about Python. To prepare yourself to recognize and address those misconceptions, perform a self-check on Progmiscon.org, a research-based inventory of programming language misconceptions. This prepares you to recognize misconceptions like AssignCompares or OutsideInFunctionNesting.

  • 💡
    Tasks

    Each activity involves one or more small programming tasks. Tasks are indicated with 🎯, usually above the corresponding code cell, and inside the code with comments.

  • 💡
    Placeholders

    In the code, we use ... as a placeholder for students to fill in. Students are supposed to replace the placeholder with the required code. If they do not replace a placeholder, this will lead to an error when they run the code.

  • 💡
    Errors

    A major part of learning to program is learning to understand and fix errors. If an error happens when running the code, the error is shown below the corresponding code cell. Common kinds of errors are NameError, SyntaxError, TypeError, and ImportError. Note that the error message includes the line number (and a copy of the line) where the error happened. This information is essential for finding and fixing the mistake.

  • 💡
    Stuck? Code Messed Up?

    If a student is stuck in an activity, for example because they receive errors that they cannot figure out how to fix, they can reset a code cell (three-vertical-dot button at its bottom right) to its original contents.

  • 💡
    TypeError

    A common TypeError is if students forget to replace a ... (also known as an ellipsis) with their own code. Often that error happens when show_graphic tries to show the value it receives as an argument, but that value is a ... instead of a valid Graphic. This leads to the following error: TypeError: Invalid type for parameter graphic: expected Graphic, got ellipsis

  • 💡
    NameError

    If students misspell a name (e.g., they write agical_battlement instead of magical_battlement), they may receive a NameError. Sometimes students introduce NameErrors because they select text to copy and paste, but their selection does not include the entire word. In our experience, NameErrors are easier to fix for many students.

  • 💡
    SyntaxError

    If students modify the structure of the code so it violates the Python grammar, they get a SyntaxError. Common reasons are unmatched parentheses, such as ((...) or ([...), or missing commans, such as wall(purple no_borders).

  • 💡
    ImportError

    If students modify one of the import statements and they end up importing a name that does not exist, they will get an ImportError.

Beyond this Hour of Code

This Hour of Code can be a great introduction for a sequence of lessons in Python programming. If you intend to continue with Python in your classroom, you may want to use the PyTamaro graphics library that underlies this Hour of Code. If you do, then consider printing out some TamaroCards to use in unplugged activities.

Content: Programming

Composition of a Castle

Learners compose castles from prefabricated pieces. We provide a function to create each piece (roof, battlement, wall, and drawbridge). We also provide two functions to compose lists of pieces, by placing them above each other (above_list) or beside each other (beside_list). The castle is composed of several pieces, such as walls, battlements, and towers. Each piece is a Graphic. The castle is composed by calling functions that produce pieces and then compose them. For example, the castle is composed by calling the function castle, which calls the functions wall, battlement, and tower.

Photo of Castle

This activity introduces students to one of the fundamental concepts in programming: the idea of a function. Functions are a way to organize code into reusable, independent, pieces. A function takes some values, and produces a result. Values are explicitly passed to a function as arguments. The result is returned by the function as a return value.

No Input, No Outside State
Arguments
Diagram of a pure function
Return Value
No Output, No Outside State

A pure function communicates exclusively through its arguments and return value. It does not read or write any state outside of the function, and it does not communicate with the world outside the computer (it does not receive input or produce output). Pure functions can be understood in isolation, without understanding anything about the rest of the program.

This provides a beautiful approach to problem decomposition we can decompose a problem into independent subproblems, decompose those subproblems into smaller independent subproblems, until they are small enough so we can solve them directly. Because of their independence, we do not have to worry about other subproblems while focusing on one.

Diagram of Problem Decomposition and Solution Composition

Pure functions are a great way to solve independent subproblems. They are also ideal for composing the solutions of multiple independent subproblems into a single solution. Besides this educational advantage, pure functions also make programs more secure, and they simplify distributed computation in modern data centers and supercomputers.

The Python library used for the graphics in this activity, PyTamaro, consists of a small set of such pure functions. Some of those functions produce a graphic (a castle piece) based on some information (like its color) passed as arguments. Other functions compose multiple pieces (passed as arguments) into a larger castle.

The pure functions in this activity can be seen in the same way as functions in mathematics. It's just that our PyTamaro functions play with graphics instead of numbers.

The Truth Behind Our Prefabricated Pieces

This tutorial provides functions to create four different kinds of prefabricated pieces: walls, roofs, battlements, and drawbridges. Did you realize that these prefabricated pieces are themselves composed of smaller parts? They are entirely composed of rectangles, triangles, ellipses, and circular sectors. Someone (the Bachelor students designing this Hour of Code) programmed those four prefabricated piece functions, so that they compose primitive graphics into the prefabricated pieces used in this tutorial. If you would like, you can create completely different pieces yourself! Check out the Welcome Curriculum on this web site to learn more.

Learning Objectives in Programming

Here are the activities and the learning objectives of the 'Program Your Own Castle' curriculum:

Perform OutputDistinguish CommentsPass ArgumentsInvoke FunctionsReceive Return ValueImport NamesUse NamesDefine NamesLiteral Lists
Show a Plain Wall
Show an Entrance
Show a Simple Battlement
Show a Magical Battlement
Choose your Favorite Wall
Close the Drawbridge
Create a Roof
Create a Battlement
Create a Wall
Building a Tower
Building a Curtain Wall
Program Your Own Castle

More information is available on the curriculum's information page.

More Educational Programming Activities Used in Swiss High Schools

If you would like to learn more about Python programming using the graphical PyTamaro approach, have a look at the many activities and curricula on this web site. They are freely available online. Many of them are in use for teaching programming in Swiss high schools. Some were developed by high school teachers themselves. We recommend you start with the Welcome Curriculum.

Should you end up using the activities in your classroom, we would be very happy to hear from you. We are developing and maintaining this web site as part of our research on how to effectively teach programming. Hearing what worked, and what did not work, can help us a great deal!

Content: History

This Hour of Code was inspired by the medieval castles that form the Fortezza Bellinzona. While the story of the oldest castle, Castelgrande, goes back to the Roman Empire, most of the fortification was built in the Late Middle Ages, in the fourteenth and fifteenth centuries.

Historical Timelne of Fortezza Bellinzona

You can learn more on the official Fortezza Bellinzona web site. Or if you have a chance to visit the mediterranean Swiss canton of Ticino, just south of the Alps, and north of the Italian cities of Como and Milan, you could visit this medieval fortress in the Swiss city of Bellinzona in person. It is a UNESCO World Heritage Site that is unique in Europe, consisting of three separate castles and their fortifications!

Glossary of Castle Architecture

Here are the terms relevant for our tutorial with photos we took at the three castles of the Fortezza Bellinzona.

Photo of Battlement
Battlement

The top part of a wall, between chest-height and head-height, holding a sequence of merlons and crenels (gaps).

Photo of Curtain Wall
Curtain Wall

The defensive wall between two fortified towers, often topped with a battlement.

Photo of Drawbridge
Drawbridge

A movable bridge usually at the entrance of a castle. The Montebello castle in Bellinzona is protected with a sequence of two drawdriges.

Photo of Merlon
Merlon

Solid upright part of a battlement between two crenels (gaps). There are many different shapes of merlons.

Literature on Castles

J. E. Kaufmann & H. W. Kaufmann; Robert M. Jurga (Illustrator). The Medieval Fortress: Castles, Forts, And Walled Cities Of The Middle Ages. Da Capo Press, 2004. ISBN 978-0-306-81358-0.

David Macaulay. Castle. Clarion Books, 2013. ISBN 978-0-544-10226-2.

Horst Wolfgang Böhme, Reinhard Friedrich, Barbara Schock-Werner (Hrsg.) Wörterbuch der Burgen, Schlösser und Festungen. Heidelberg: arthistoricum.net-ART-Books, 2020.

The Hour of Code ® is an initiative by Code.org to introduce millions of students to one hour of computer science and computer programming, especially during CSEdWeek, the computer science education week that takes place every year during the week of Grace Hopper's birthday (December 9, 1906), a pioneer of computer science who invented the first compiler and coined the term “bug”.
Hour of Code® and Hora del Código® are registered trademarks of Code.org.

Logo of PyTamaro

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

Privacy PolicyPlatform Version f9e590c (Sun, 19 May 2024 10:38:32 GMT)