Exercises
Use IPython sessions for each exercise where practical.
5.1 (What’s Wrong with This Code?) What, if anything, is wrong with each of the following code segments?
-
day, high_temperature = ('Monday', 87, 65)
-
numbers = [1, 2, 3, 4, 5]
numbers[10]
-
name = 'amanda'
name[0] = 'A'
-
numbers = [1, 2, 3, 4, 5]
numbers[3.4]
-
student_tuple = ('Amanda', 'Blue', [98, 75, 87])
student_tuple[0] = 'Ariana'
-
('Monday', 87, 65) + 'Tuesday'
-
'A' += ('B', 'C')
-
x = 7
del x
print(x)
-
numbers = [1, 2, 3, 4, 5]
numbers.index(10)
-
numbers = [1, 2, 3, 4, 5]
numbers.extend(6, 7, 8)
-
numbers = [1, 2, 3, 4, 5]
numbers.remove(10)
-
values = []
values.pop()
-
5.2 (What’s Does This Code Do?) What does the following function do, based on the sequence it ...
Get Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.