From c8a71b86d885d59f009362790351620c599fbfa3 Mon Sep 17 00:00:00 2001 From: halidickson <63528283+halidickson@users.noreply.github.com> Date: Wed, 15 Apr 2020 21:31:32 -0700 Subject: [PATCH 1/4] lesson 5 --- lessonFive.py | 29 +++++++++++++++++++++-------- lessonFour.py | 23 +++++++++++++++-------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/lessonFive.py b/lessonFive.py index b0ab152..962c0a6 100644 --- a/lessonFive.py +++ b/lessonFive.py @@ -17,33 +17,46 @@ # only if the length of the list is less than 5. def addToList(element) : # your code here - + 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 - - + myList.pop() + 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 - + index = myList.index(element) + for item in myList : + return index + return -1 # 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 - + index = myList.index(element) + getIndex(element) + print (index) # 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: + index = myList.index(element) + getIndex(element) + myList.pop(index) + return myList + return -1 #-----# @@ -84,7 +97,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) From 37bcde80c97cc90d13a9e2260da95ad53bf0a63e Mon Sep 17 00:00:00 2001 From: halidickson <63528283+halidickson@users.noreply.github.com> Date: Wed, 15 Apr 2020 23:04:09 -0700 Subject: [PATCH 2/4] lesson 5 --- lessonFive.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lessonFive.py b/lessonFive.py index 962c0a6..419757a 100644 --- a/lessonFive.py +++ b/lessonFive.py @@ -17,15 +17,19 @@ # only if the length of the list is less than 5. def addToList(element) : # your code here - myList.append(element) + 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 - myList.pop() - return myList + 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. From c78f65591666229a71e5101950c7ba994d7bc2fb Mon Sep 17 00:00:00 2001 From: halidickson <63528283+halidickson@users.noreply.github.com> Date: Wed, 15 Apr 2020 23:11:54 -0700 Subject: [PATCH 3/4] lesson 5 --- lessonFive.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lessonFive.py b/lessonFive.py index 419757a..11c221b 100644 --- a/lessonFive.py +++ b/lessonFive.py @@ -25,7 +25,7 @@ def addToList(element) : # 'myList', and returns it unless there is one left, then leave it. def removeFromList() : # your code here - if len(myList) >= 1: + if len(myList) > 1: myList.pop() return myList else: @@ -58,8 +58,8 @@ def removeElement(element) : if item == element: index = myList.index(element) getIndex(element) - myList.pop(index) - return myList + return myList.pop(index) + return -1 #-----# From 713a344f03851fddeca3fc30fb18268552b041d2 Mon Sep 17 00:00:00 2001 From: halidickson <63528283+halidickson@users.noreply.github.com> Date: Wed, 15 Apr 2020 23:39:12 -0700 Subject: [PATCH 4/4] lesson 5 --- lessonFive.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lessonFive.py b/lessonFive.py index 11c221b..f2f5278 100644 --- a/lessonFive.py +++ b/lessonFive.py @@ -35,20 +35,21 @@ def removeFromList() : # If the list doesn't contain the element then return -1. def getIndex(element) : # your code here - index = myList.index(element) - for item in myList : - return index - return -1 - + 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. # Should getElement() be getIndex() from above? I'm going to assume that. def printIndex(element) : # your code here - index = myList.index(element) - getIndex(element) - print (index) + 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. @@ -56,9 +57,8 @@ def removeElement(element) : # your code here for item in myList: if item == element: - index = myList.index(element) getIndex(element) - return myList.pop(index) + return myList.pop(myList.index(element)) return -1