Question: Python Please! Accessing nested structures: What's in Debug's Picnic Basket? PURPOSE: Skills/Knowledge: understanding the relationship among nested structures accessing individual parts of a whole structures
Python Please! Accessing nested structures: What's in Debug's Picnic Basket?
PURPOSE:
- Skills/Knowledge:
- understanding the relationship among nested structures
- accessing individual parts of a whole structures
GOALS:
- Pre-requisite Knowledge:
- accessing elements of a list, namedtuple
TASK:
Use the following structure to:
from collections import namedtuple Food = namedtuple('Food','name color flavor_profile quantity') pretzel = Food('pretzel', 'brown', 'salty', 10) watermelon = Food('watermelon', 'red', 'sweet', 2) debugs_picnic_basket = [pretzel, watermelon, Food('pickle','green','sour', 5)] - 1) Access & print the flavor_profile element from the pretzel namedtuple.
- 2) Write the statement to print the 'd', within watermelon.
- 3) From debugs_picnic_basket, print the pickle namedtuple.
- 4) Write the statement to print the 'u', within the pickle namedtuple.
- 5) Sum & print the total number of items within Debug's picnic basket.

SAMPLE OUTPUT:
- Input: None required.
- Output:

from collections import namedtuple
Food = namedtuple('Food','name color flavor_profile quantity') pretzel = Food('pretzel', 'brown', 'salty', 10) watermelon = Food('watermelon', 'red', 'sweet', 2)
debugs_picnic_basket = [pretzel, watermelon, Food('pickle','green','sour', 5)]
''' Type your code here. ''' #1) Access & print the flavor_profile element from the pretzel namedtuple. #2) Write the statement to print the 'd', within watermelon. #3) From debugs_picnic_basket, print the pickle namedtuple. #4) Write the statement to print the 'u', within the pickle namedtuple. #5) Sum & print the total number of items within Debug's picnic basket.
PURPOSE: Skills/Knowledge: o understanding the relationship among nested structures o accessing individual parts of a whole structures GOALS: Pre-requisite Knowledge: o accessing elements of a list, namedtuple TASK: Use the following structure to: from collections import namedtuple Food = namedtuple ('Food', 'name color flavor_profile quantity') pretzel = Food ('pretzel', 'brown', 'salty', 10) watermelon = Food ('watermelon', 'red', 'sweet', 2) debugs_picnic basket = [pretzel, watermelon, Food ('pickle', 'green', 'sour', 5)] 1) Access & print the flavor_profile element from the pretzel namedtuple. 2) Write the statement to print the 'd', within watermelon. 3) From debugs_picnic basket, print the pickle namedtuple. 4) Write the statement to print the 'u', within the pickle namedtuple. . 5) Sum & print the total number of items within Debug's picnic basket. main.py Load default template... 1 from collections import named tuple 2 3 Food = namedtuple('Food', 'name color flavor-profile quantity') 4 pretzel = Food('pretzel', 'brown', 'salty', 10) 5 watermelon = Food('watermelon', 'red', 'sweet', 2) 6 7 debugs_picnic_basket = [pretzel, watermelon, Food('pickle','green', 'sour', 5)] 8 9 "Type your code here. 10 #1) Access & print the flavor_profile element from the pretzel namedtuple. 11 #2) Write the statement to print the 'd', within watermelon. 12 #3) From debugs_picnic basket, print the pickle namedtuple. 13 #4) Write the statement to print the 'u', within the pickle namedtuple. 14 #5) Sum & print the total number of items within Debug's picnic basket.||
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
