Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use the Python Language, preferabally 2.7, to solve this two probem set a

ID: 3874401 • Letter: P

Question

Please use the Python Language, preferabally 2.7, to solve this two probem set about while loops. The parameters and answer template for the solution is also given beneath the problem descriptions.

Its contents are as follows:

#PROBLEM 1
def addOne(l1):

    list1 = l1
    
    return 0
    
    #YOUR CODE GOES HERE (indented)

    return l1
    #END YOUR CODE

    
#PROBLEM 2
def checkIn(l1,l2):
    string1 = l1
    string2 = l2

    #YOUR CODE GOES HERE (indented)

    return string1
    #END YOUR CODE     

Problem 1: Write code that adds 1 to every element in a list. For example, the list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] would yield [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]. You may not use any built-in functions/methods besides len()and .append(). Problem 2: Write code that takes two strings from the user, and sees if all the letters in the second string appear in the first, in order. For example, happybirthday and apt yields the result True, while happybirthday and htb yields the result False.

Explanation / Answer

def addOne(l):
    for i in range(len(l)):
        l[i] = l[i]+1
    return l

def checkln(l1,l2):
    list = []
    for i in range(len(l2)):
       for j in range(len(l1)):
           if l2[i] == l1[j]:
              list.append(j)
              break
   
    if len(list)==len(l2):
       for i in range(1,len(list)):
           if list[i] < list[i-1]:
              return False
       return True
    return False
       

print(addOne([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
print(checkln("happybirthday","apt"))
print(checkln("happybirthday","htb"))