Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 89 2nd Symposium On Mathematical Fundamentals Of Database Systems Visegrad Hungary June 26 30 1989 Proceedings

Authors: Janos Demetrovics ,Bernhard Thalheim

1989th Edition

3540512519, 978-3540512516

More Books

Students also viewed these Databases questions