Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions lessonFive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one just needs to return 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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to return -1 a lot. It's kind of like the same thing you fixed in the last exercise

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

#-----#

Expand Down Expand Up @@ -84,7 +101,7 @@ def removeElement(element) :
printIndex(13)

print("6: ")
printIndex(13)
printIndex(6)

elem = removeElement(13)
print("removed 13: ", elem)
Expand Down
23 changes: 15 additions & 8 deletions lessonFour.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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)
print('complexSum([2, 4, 6, 8, 10]) ', execute)