Before you turn in this homework, make sure everything runs as expected. First, restart the kernel (in the menubar, select Kernel$\rightarrow$Restart) and then run all cells (in the menubar, select Cell$\rightarrow$Run All).
Make sure you execute every single code cell, in order, filling with your solutions in any place that says YOUR CODE HERE
, and always DELETE the line that says:
raise NotImplementedError()
The purpose of this line is to tell you if you forgot to answer a question (it will throw an error if the line is there)
IMPORTANT: DO NOT DELETE ANY CELL.
Fill your name below:
NAME = ""
Given the list named pizzas
:
pizzas = ['cheese', 'pepperoni', 'margherita', 'hawaiian', 'italian sausage', 'green peppers and onions']
Grab the first flavor, assign the value to a variable named first_flavor
, and print it.
### BEGIN SOLUTION
first_flavor = pizzas[0]
print(first_flavor)
### END SOLUTION
cheese
#BEGIN HIDDEN TESTS
from nose.tools import assert_equal
assert_equal(first_flavor, 'cheese')
#END HIDDEN TESTS
Grab the last flavor, assign the value to a variable named last_flavor
, and print it.
### BEGIN SOLUTION
last_flavor = pizzas[-1]
print(last_flavor)
### END SOLUTION
green peppers and onions
#BEGIN HIDDEN TESTS
assert_equal(last_flavor, 'green peppers and onions')
#END HIDDEN TESTS
Access the element of the pizza list that corresponds to 'pepperoni', replace it for 'mushroom', and print the pizzas list.
### BEGIN SOLUTION
pizzas[1] = 'mushroom'
print(pizzas)
### END SOLUTION
['cheese', 'mushroom', 'margherita', 'hawaiian', 'italian sausage', 'green peppers and onions']
#BEGIN HIDDEN TESTS
assert_equal(pizzas, ['cheese', 'mushroom', 'margherita', 'hawaiian', 'italian sausage', 'green peppers and onions'])
assert_equal(pizzas[1], 'mushroom')
#END HIDDEN TESTS
Before you turn this problem in, make sure everything runs as expected. First, restart the kernel (in the menubar, select Kernel→→Restart) and then run all cells (in the menubar, select Cell→→Run All).
Make sure you filled in any place that says YOUR CODE HERE or "YOUR ANSWER HERE", as well as your name at the beggining of the notebook.