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 #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 ctrStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started