The CTP Book

A book for teaching Computational Thinking and Programming skills to people with a background in the Humanities

View on GitHub

Chapter “Organising information: unordered structures”, exercise 1

Text

Write a code in Python to create a set of the following elements: "​Bilbo", "​Frodo", "​Sam", "​Pippin", "​Merry".

Answer

my_set = set()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Sam")
my_set.add("Pippin")
my_set.add("Merry")

Additional material

The runnable Python file is available online.