Given the list:
fruits = ['apple', 'orange', 'banana']
How would you access the item 'orange'?
fruits[1]
farm_data = {'crop': 'corn', 'acres': 50}
'corn'
What value does this print?
animals_weights = [110, 140, 200]
print(animal_weights[1])
140
How many times will this for loop run?
for i in range(5):
print("Hello")
5
What is the variable i going to be at the end of the loop?
i = 0
while i < 3:
i += 1
3
Fill in the blank to add a new animal to the end of the list:
animals = ['cow', 'pig']
animals.___('chicken')
animals.append('chicken')
Add a new key-value pair: 'milk_yield': 30 to the following dictionary:
cow = {'breed': 'Holstein'}
cow['milk_yield'] = 30
OR
cow.update({'milk_yield': 30})
OR
kv_pair = {'milk_yield': 30}
cow.update(kv_pair)
Fill in the blank to calculate the average value of the array:
yields = np.array([150, 160, 155])
avg = np.___(yields)
np.mean(yields)
Fill in the blank to print each item of a list called crops:
for crop in ___:
print(crop)
crops
Fill in the blank to print "Water level is low" until the level is 10:
level = 5
while level __ 10:
print("Water level is low")
level += 1
<=
What is the value and the type of ls_length if:
livestock = ['sheep', 'goats']
livestock.append('chickens')
ls_length = len(livestock)
ls_length is 3, type is 'int'
What is the output of this code?
animal_weights = {'cow': 500, 'pig': 200}
animal_weights['pig'] = 220
print(animal_weights['pig'])
220
How do you get the number of values in this numpy array?
temps = np.array([22, 23, 14]
len(temps)
What is the output of this code?
total = 0
for number in [10, 20, 30]:
total += number
print(total)
60
How many times will "The tractor is running" be printed?
fuel = 5
while fuel > 0:
print("Tractor is running")
fuel -= 2
1st) fuel = 5; -2
2nd) fuel = 3; -2
3rd) fuel = 1; -2 - DONE
What is the value of new_list?
daily_temps = [65, 70, 72, 75, 71, 68]
new_list = daily_temps[1:4]
[65, 70, 72]
What value is going to be printed?
temps = {'field1': 75, 'field2': 81, 'field3': 79}
my_temp = temps.get('field4', 79)
79
Resize/reshape this array to have 4 columns and 3 rows.
my_arr = np.array([1, 1, 1, 0, 0, 2, 0, 0, 0, 3, 3, 4])
new_arr = my_arr.reshape((4, 3))
OR
my_arr.resize((4, 3))
What is the final value of the variable count?
count = 0
for temp in [75, 80, 68, 85]:
if temp > 70:
count += 1
3
Find the issue with this code so that it counts from 1 to 5.
count = 1
while count < 5:
print(count)
count += 1
Option 2) Count starts from 0; and the print goes after the increment of count.
What is the output of this code?
weights = [3, 1, 5, 4, 6, 2, 10]
weights.remove(2)
print(weights)
[3, 1, 5, 4, 6, 10]
How do you remove 'field2' (and its value) from the following dictionary?
temps = {'field1': 75, 'field2': 81, 'field3': 79}
del temps['field2']
OR
var = temps.pop('field2')
Create a numpy array of 10 random values, in a range from 0 to 100.
rnd_arr = np.random.randint(0, 100, 10)
What is the output of this nested loop?
for animal in ['cow', 'pig']:
for feed in ['hay', 'grain']:
print(animal + ' eats ' + feed)
cow eats hay
cow eats grain
pig eats hay
pig eats grain
What will be the final value of population?
population = 10
growth = 2
while population < 20:
population += growth
print(population)
20