Question: functions and loops help ListsOfiteration.py SubmitRun Grades Reset We tested your code with given -items = [ 'one', 'two', 3, 4, i given-items [one, two,

functions and loops help ListsOfiteration.py SubmitRun Grades Reset We tested your codefunctions and loops help

ListsOfiteration.py SubmitRun Grades Reset We tested your code with given -items = [ 'one', 'two', 3, 4, i given-items ["one", "two", 3, 4, "five", ["six", "seven", "eight"]] 3 #Write a program that iterates through the items in the five', ['six', 'seven', 'eig ht'1]. We expected your code t o print this: 4 #given list. For each item, you should attempt to iterate 5 #through the item and print each character seperately 7 #If this second part fails, print "Not iterable"-but 8 #even if the second part fails, you should still go on 9 #to the next item in the list. 10 # 11 #Hint: Although we'll cover lists more in Unit 4, all 12 #you need to know right now is that this syntax will run 13 #a loop over a list, a string, or any 14 #type of information: 15 # 16 # for item in given items: 17 # 18 #To iterate over the items in "item", you can do the 19 #same thing: for subitem in item: 20 # other iterable Not iterable Not iterable 21 #start out by building the nested for-each loops that 22 #you'll need. Then, identify where the error is 23 #oc curring to figure out where to put the try-except 24 #structure 25 # 26 #This one's tricky, but you can do it! 27 28 29 #Add your code here! 30 def iteration (given items): 31 32 six seven eight However, it printed this: one for item in given items: for subitem in given items: try: five 34 print (subitem) ['six', 'seven''eight'] one except: rint"Not iterable") 36 37 iteration(given_it 38 39 five ['six', 'seven', eight'] one five six, 'seven, 'eight'] one ['six', 'seven',eight'1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!