Question: #The following code adds 1 to every element in a list #like list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] would yield

 #The following code adds 1 to every element in a list

#The following code adds 1 to every element in a list #like list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] would yield

#[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]. No built-in

#functions/methods can be used besides len() and #.append(). #I had trouble programming the code to pass tests

#cases listed at the end

def addOne(l1):

list1 = l1

#creates a new list

new_list = []

#initialize index

ctr = 0

#loop around the length of list1

while ctr

#add 1 to every in this list

###HAVING ISSUES STARTING HERE

new_list[ctr] = list1(new_list[ctr] + 1)

#increment indices

ctr += 1

#return new_list

return new_list

#test cases:

checkIn (bird, c)

#False

checkIn (bird, i)

#True

#checkIn (bird, ir)

#True

#checkIn (bird, bd)

#True

#checkIn (bird, db)

#False

#checkIn (birkugyfjydhrsfbdsd, bkujds)

#True

#checkIn (birkugyfjydhrsfbdsd, bkjuds)

#False

PROBLEM 1 2 Edef addOne (11): 3 4 5 6 listl- 11 #creates a new list new list-[ #initialize index ctr 0 #loop around the length of list! while ctr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!