1. Add a new student 2. Update a student's grade 3. Display a student's grade 4. Remove a student 5. Quit
bread = { 'title': "Grandma's Honey Whole Wheat Bread", 'ingredients': { 'honey': '8 oz', 'oil': '3.5 oz', 'water': '3.1 pounds', 'whole wheat flour': '4.5 - 4.75 lbs', 'yeast': '3 Tablespoons', 'salt': '1.5 Tablespoons' }, 'servings': 84, 'Nutrition Facts': { 'calories': 105.5, 'total fat': '1.6 g', 'sodium': '118.2 mg', 'potassium': '3.3 mg', 'carbohydrates': { 'total': '21.1 g', 'dietary fiber': '3.2 g', 'sugars': '2.2 g' }, 'protein': '3.5 g' } }What do each of the following display:
print( '\nbread.keys()') for variable in bread.keys(): print( variable )
print( '\nbread.values()') for variable in bread.values(): print( variable )
print( '\nbread.items()') for variable in bread.items(): print( variable )
print( '\nbread') for variable in bread: print( variable )
trailMix = { } trailMix['title'] = 'Trail Mix' ingredientsDictionary = dict( peanuts = '2 cups', raisins = '2 cups', MandMs = '1 1/2 cups' ) trailMix['ingredients'] = ingredientsDictionary trailMix['instructions'] = 'Combine all ingredients' recipes = [] recipes.append( bread ) recipes.append( trailMix ) nutritionFactsLabel = 'Nutrition Facts' for recipe in recipes: title = recipe.get('title', 'No title') _________________: print( f"{title}'s {nutritionFactsLabel}:" ) for nfKey in recipe[nutritionFactsLabel]: print( nfKey + ': ' + str(recipe[nutritionFactsLabel][nfKey]) ) else: print(f'Note, {title} does not have {nutritionFactsLabel} information')
gourmetTrailMix = dict( trailMix ) gourmetTrailMix['title'] = 'Gourmet Trail Mix' print( 'gourmetTrailMix:', gourmetTrailMix ) print( 'trailMix:', trailMix )
# assumes that ingredients is a valid key gourmetTrailMix['ingredients']['almonds'] = gourmetTrailMix['ingredients']['peanuts'] del gourmetTrailMix['ingredients']['peanuts'] print( 'gourmetTrailMix:', gourmetTrailMix ) print( 'trailMix:', trailMix )