Enter your name and EID here
This homework is due on Mar. 30, 2020 at 12:00pm. Please submit as a PDF file on Canvas. Before submission, please re-run all cells by clicking "Kernel" and selecting "Restart & Run All."
Problem 1 (5 pts): Create a list with the names of your favorite foods. Your list should contain at least 5 different kinds of food. Then, complete the following steps using python. Each step should be completed in a different cell and your results should be printed with print()
.
.sort()
.len()
..remove()
.append()
food = ['tacos', 'sushi', 'pizza', 'shawarma', 'pho']
print(food)
food.sort()
print(food)
print(len(food))
food.remove('shawarma')
print(len(food))
food.append('falafel')
print(food)
new_food = food * 5
print(new_food)
Problem 2 (5 pts): Now imagine that you have spent a week eating only your favorite foods listed in Problem 1. Create a dictionary that contains the names of the food as keys & counts for each time you ate that food as values. For example, if you ate tacos 12 times, the key would be "tacos" and the value would be 12. The counts should just be made-up counts. Then, complete the following steps using python. Each step should be completed in a different cell and your results should be printed with print()
.
for
loop..keys()
and .values()
.food_dict = {'pizza': 5, 'pho': 2, 'tacos': 7, 'sushi': 1, 'falafel': 3}
print(food_dict)
total = 0
for key in food_dict.keys():
total += food_dict[key]
print(total)
food_dict['ramen'] = 7
print(food_dict)
print(food_dict.keys())
print(food_dict.values())
food_dict['ramen'] = 10
print(food_dict)
del food_dict['pho']
print(food_dict)