diff --git a/lessonFive.py b/lessonFive.py index b0ab152..f2f5278 100644 --- a/lessonFive.py +++ b/lessonFive.py @@ -17,33 +17,50 @@ # only if the length of the list is less than 5. def addToList(element) : # your code here - + if len(myList) <= 5: + myList.append(element) + return myList # Complete a function that removes the last element from the list # 'myList', and returns it unless there is one left, then leave it. def removeFromList() : # your code here - - + if len(myList) > 1: + myList.pop() + return myList + else: + return myList # Complete a function that returns the index of 'element'. # If the list doesn't contain the element then return -1. def getIndex(element) : # your code here - - + for item in myList: + if item != element: + return -1 + elif item == element: + return myList.index(element) # Complete a function that calls getElement() and prints the value -# it returns. +# it returns. +# Should getElement() be getIndex() from above? I'm going to assume that. def printIndex(element) : # your code here - + for item in myList: + if item == element: + getIndex(element) + print (myList.index(element)) # Complete a function that removes the element 'element' from the # list and returns it. If the element doesn't exist, then return -1. def removeElement(element) : # your code here - + for item in myList: + if item == element: + getIndex(element) + return myList.pop(myList.index(element)) + + return -1 #-----# @@ -84,7 +101,7 @@ def removeElement(element) : printIndex(13) print("6: ") -printIndex(13) +printIndex(6) elem = removeElement(13) print("removed 13: ", elem) diff --git a/lessonFour.py b/lessonFour.py index d3b237c..d1d205f 100644 --- a/lessonFour.py +++ b/lessonFour.py @@ -1,37 +1,44 @@ # complete this function so that it prints Hello, World def printHelloWorld() : # your code here - + print ("Hello World") # complete this function so that it prints whatever is provided in the parameter def printParam(param) : # your code here - + print (param) # complete this function so that it returns the sum of num1 and num2 def sumTwoNumbers(num1, num2) : # your code here - + sum = num1 + num2 + return sum # complete this function so that it returns the square of the num parameter def findSquare(num) : # your code here - + square = num * num + return square # complete this function so that it returns True if day is Wednesday # otherwise return False def dayIsWednesday(day) : # your code here - - + print (day) + myList = [ "mainsheet", "batton", "rudder", "foil", "block" ] # complete this function so that it return "I got it" if item is in myList # otherwise return "I have to get it" def findInList(item) : # your code here + for part in myList: + if part == item : + return ("I got it!") + + return ("I have to get it!") # assuming every element in 'numList' is a number, complete this function so that it # returns the total sum of the elements in the list def complexSum(numList) : # your code here - + print ("Complex Sum") printHelloWorld() @@ -59,4 +66,4 @@ def complexSum(numList) : print('complexSum([1, 3, 5, 7, 9]) ', execute) execute = complexSum([2, 4, 6, 8, 10]) -print('complexSum([2, 4, 6, 8, 10]) ', execute) \ No newline at end of file +print('complexSum([2, 4, 6, 8, 10]) ', execute)