Enumerations – Practical Use, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
Enumerations – Practical Use in one minute
What students need to know
+ creates a new tuple containing all items from both tuples. count() is one of the few methods tuples support.
Adding two tuples joins them into a new tuple - the result keeps the tuple type. Multiplying repeats the whole tuple - 3 copies of (1,2) joined together.
Mistakes students make
- Tuples don't have sort(). Use sorted() and convert back.
- Must concatenate with a tuple: (4,) not just 4.
- index() raises ValueError if value isn't in the tuple.
- sorted() returns a list. Wrap in tuple() to get a tuple back.
PREVIOUS · MODULE 57Enumerations – Basics
YOU ARE HERE · MODULE 58Enumerations – Practical Use
NEXT · MODULE 59Tuples – Basics
What students will learn in this module
Every question in Module 58
Quick questions
- (1,2) + (3,4) returns?A[1, 2, 3, 4]B(1, 2, 3, 4)
- (1,2) * 3 returns?A(1, 2, 1, 2, 1, 2)B(3, 6)
- t = (1,2,2,3)\nt.count(2) returns?A2B1
- t = (10,20,30)\nt.index(20) returns?A1B20
- How many methods do tuples have?AMany like listsBJust 2: count() and index()
Key terms
Students type the meaning of:
Concatenation (+)Repetition (*).count(value).index(value)
Match the pairs
t.append(4)Match it to what it doest.remove(1)Match it to what it does(1, 2) + (3, 4)Match it to what it doest.count(2)Match it to what it does(1, 2) * 2Match it to what it doessorted((3, 1, 2))Match it to what it doesFill in the blanks
t = (1, 2) _ (3, 4)
t = (1, 2) _ 3
t = (1, 2, 2, 3) print(t._____(2))
t = (10, 20, 30) print(t._____(20))
t = (3, 1, 2) print(______(t))
Spot the error
Question 1
At = (3, 1, 2)Bt.sort()Cprint('Sorted:', t)Dprint('Done')
Question 2
At = (1, 2, 3)Bt += 4Cprint('Tuple:', t)Dprint('Done')
Question 3
At = (1, 2, 3)Bidx = t.index(5)Cprint('Index:', idx)Dprint('Done')
Question 4
At = (3, 1, 2)Bresult = sorted(t)Cprint('Sorted:', result)D# expects tuple
Question 5
At = (1, 2) + [3, 4]Blabel = 'Combined'Cprint('Combined:', t)Dprint('Done')
