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

using python 3: csis 153 Bonus opportunities #2 (15 bonus points) 1. Create a Py

ID: 3828462 • Letter: U

Question

using python 3:

csis 153 Bonus opportunities #2 (15 bonus points) 1. Create a Python function called sum Threezero. lt should accept a list of numbers and should return a list of sublists of three numbers from the list such that the sum of three numbers is equal to zero Examples nums 1,0,1,2,-1 print sumThreezero (nums1)) #output is [[-1, -1, 2], D-1, 0, 1]] nums3 I-25,-10,-7,-3, 2,4,8,10] print sumThreezero nums #output is II-10, 2, 8), [-7, -3, 10ll 2. Create a Python function called findMissing which accepts a list of numbers and returns a list of the missing numbers from that list Examples myList [1,2,3,4,7, 101 print (findMissing(myList) #output [5,6,8,9] myList [10, 11,12,14,15,17] print find Missing (myList #Output is [13, 16] 3. Create a function called gensentences to generate all sentences which accepts 3 parameters subjList, verbList, objectList. It should return a list of strings where each string is a sentence that begins with a word from the subj List, then uses a verb from the verbList, and finally uses an object from obList Example sList- I'l", You' I, VList play", enjoy"], oList Hockey", "Football results genSentences(sList, vList, oList) for sent in results print(sent) #output should be I play Hockey I play Football I enjoy Hockey I enjoy Football You play Hockey You play Football You enjoy Hockey You enjoy Football

Explanation / Answer

1.

def sumThreeZero(numbers):
if len(numbers)<3:
   return []
numbers.sort()
result=[]
for i in range(len(numbers)-2):
start=i+1
end=len(numbers)-1
if i!=0 and numbers[i]==numbers[i-1]:
   continue
while start<end:
if numbers[start]+numbers[end]==-numbers[i]:
result.append([numbers[i],numbers[start],numbers[end]])
start=start+1
end=end-1
while numbers[start]==numbers[start-1] and start<end:
   start=start+1
while numbers[end]==numbers[end+1] and start<end:
   end=end-1
elif numbers[start]+numbers[end]<-numbers[i]:
start=start+1
else:
end=end-1
return result
nums2 = [-25,-10,-7,-3,2,4,8,10]
print(sumThreeZero(nums2))

2.

def findMissing(L):
start, end = L[0], L[-1]
return sorted(set(range(start, end + 1)).difference(L))
myList = [1,2,3,4,7,10]
print(findMissing(myList))

3.

# your code goes here
def genSentences(subList,vList,objList):
   res = []
   for i in subList:
       for v in vList:
           for o in objList:
               res.append(" ".join([i,v,o]))
   return res
sList = ["I","You"]
vList = ["play","enjoy"]
objList = ["Hokey","FootBall"]
res = GetSentence(sList,vList,objList)
for r in res:
   print(r)