What is `age` called the following code
def can_drive(age):
return age >= 18
parameter
Define a variable x that is a list with 2 items
x = [3, 4]
In the following loop. What should replace [missing]?
for i [missing] range(4):
print(i)
in
What is the length of table
table = [['Popeye', 20], ['Jelly', 200]]
2
Define a variable called 's' that contains a new empty dictionary
s = {}
What does the following print
def mystery(val)
return (val * 2) - 3
x = mystery(5)
print(mystery(x))
11
print(len(players))
Write a for loop to print out all items from `shows`
shows = ['DS9', 'Enterprise', 'Next Generation']for s in shows:
print(s)
How can you determine if something is a 2D list
A list that only contains other lists
How can you determine whether a value is a tuple?
A list of values separated by commas surrounded by parenthesis
What is the order that the following lines of code will be executed:
1. def multiply_5(num):
2. return num * 5
3. x = multiply_5(20)
4. print(x)
1, 3, 1, 2, 3, 4
Why would you use a list instead of a tuple?
You cannot mutate a tuple
What does the following print?
prices = {'bananas': 4, 'apples': 2, 'oranges': 5}
for c in prices:
if prices[c] % 2 == 0:
print(c)
bananas
apples
What is the value of x
board = [['B', 'E', 'M', 'O'], ['F', 'I', 'N', 'N'], ['J', 'A', 'K', 'E']]
x = board[1][2]
N
Given a dictionary named `player_numbers` add a new key: 34, with the value 'Giannis'
player_numbers[34] = 'Giannis'
Define a function that takes two parameters, a list and a number. The function should return true if the length of the list greater than the number
def func(lst, num):
return len(lst) > num
Write code to loop through a list `numbers` and create a new list `over_ten` that contains all values in `numbers` that are greater than 10
over_ten = []
for n in numbers:
if n > 10:
over_ten.append(n)
When can you not use a for loop to execute a block of code a number of times
When you don't know how long you are going to loop
Write the code to change the value 'Hey' in the list below to 17
table = [[55, 100, 22], [45, 33, 11], ['Hey', 2, 111]]
table[2][0] = 17
How many keys does `scores` have after the following code:
scores = {'sam': 50, 'legolas': 25}
scores['gimli'] = 99
scores[25] = 'gandalf'
4