Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Bookmarks People Window Help hway I Math Proble x SakalauRI csc 110 x group act2

ID: 3789275 • Letter: B

Question

Bookmarks People Window Help hway I Math Proble x SakalauRI csc 110 x group act2a-list-ops-s x Homework ccessVlessonbuilder/item/11776503/group/e3dbb580-1615-490f-aff0-88f96032a87c/Weekly9%2 1. What is the output of the following programs? (D not use your computer for this) Program 2 Program 1 mammals can 'dog', lion 'elephant'] list [1, 2, 3, 4, 5] list2 [10, 20, 301 birds duck 'parrot' list 3 15, 10, 15, 20, 25, 301 reptiles t's take 'lizard 'turtle' mammals mamm is 2 del list 2121 list3 list3 1:41 my zoo birds mammals list2 extend (list3) my zoo [2] ren less [2] list2 remove (10) listl tol list2 pop (0) my zoo insert (4 'frog') list 3 reverse my zoo append ('goose') if len (my zoo) 8: print (list1) print (list 2) my zoo remove ('dog') print (list 3) else: my zoo append ('sheep') print (my zoo) output: output:

Explanation / Answer

""" AUTHOR : FILE NAME : program1.py DATE : 8/2/17 """ list1 = [1, 2, 3, 4, 5] list2 = [10, 20, 30] list3 = [5, 10, 15, 20, 25, 30] # del function will delete the element at given index from list # here list is list2 and index is 2 (index start from 0) # so after running below statement second element will be deleted form list 2 means 30 will we deleted del list2[2] # now list2 have [10,20] # list[start_index:end_index] this is slicing expression start_index is inclusive but end_index exclusive # so we are assigning part of list3 to list3 itself list3 = list3[1:4] # list3=[10,15,20] beacuse list3[1:4] =[10,20,30] list2.extend(list3) # here concatenating two list list2.remove(10) # removing 10 from list2 ,do not confuse here 10 is value not index list1[0] = list2.pop(0) # here removing element at index 0 from list2 and assigning to list1 at index 0 list3.reverse() # reversing the list print(list1) print(list2) print(list3) # output: """ [20, 2, 3, 4, 5] [10, 15, 20] [20, 15, 10] """ """ AUTHOR : FILE NAME : program2.py DATE : 8/2/17 """ mammals = ['cat', 'dog', 'lion', 'elephant'] birds = ['duck', 'parrot'] reptiles = ['snek', 'lizard', 'turtle'] mammals = mammals * 2 # here we are extending list by itself my_zoo = birds + mammals[:6] # here we assigning my_zoo variable with birds and 6 element form mammals my_zoo[2] = reptiles[2] # assigning element at index 2 from reptiles to my_zoo at index 2 my_zoo.insert(4, 'frog') # inserting frog at index 4 my_zoo.append('goose') # appending goose at last to my_zoo if len(my_zoo) > 8: # checking the length of zoo if greater than 8 my_zoo.remove('dog') # then remove first dog from my_zoo else: my_zoo.append('sheep') # else add sheep at end print(my_zoo) # output: """ ['duck', 'parrot', 'turtle', 'frog', 'lion', 'elephant', 'cat', 'dog', 'goose'] """ """ AUTHOR : FILE NAME : program3.py DATE : 8/2/17 """ threeList = [] # creating a list for number in range(1, 50): # looping 1 to 49 if number % 3 == 0: # if number is divisible by 3 threeList.append(number) # add it to the list print(threeList) # output """ [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48] """ """ AUTHOR : FILE NAME : program4.py DATE : 8/2/17 """ myList = [1, 3, 6, 4, 2, 5] # creating a list # looping 0 to lengh of list means 0 to 5 because in range(start,end ,...) end is exclusive for i in range(len(myList)): print(myList[i] * 4) # multiplying the element at index at i by 4 and printing # output """ 4 12 24 16 8 """ AUTHOR : FILE NAME : findLargestEvenNumber.py DATE : 8/2/17 """ myList = [12, 13, 11, 24, 54, 67, 34, 78, 19, 24, 65] largest = 0; for x in myList: # iterating through list if x % 2 == 0 and x > largest: # checking for even and even and x is greater than largest assign to largest largest = x print("Largest Even Numbe:", largest) # output """ Largest Even Numbe: 78 """ 20 """

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote