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

I need to write a program getD (lst, num) with a list of chars and an integer as

ID: 3643512 • Letter: I

Question

I need to write a program getD(lst, num) with a list of chars and an integer as the parameters. I need it to return True if the difference between the encoding of each adjecent pair of characters that is in the list produces a value that is = to the second parameter. Then if any of the adjacent character pairs in the list encoding doesn't get the second parameter as the result when they are subtracted, then it needs to return False. If the list is empty, or just one value, also return False.

I know this involves the ord function, and relates to the UNICODE stuff. any help?


these are some of the example outputs


getD(['a', 'f', 'k', 'p'], 5) True getD(['Z', 'X', 'V', 'T', 'R', 'P'], 2) True getD(['#', '%', ')'], 2) False

Explanation / Answer

def getD(lst, num):
    if len(lst)<2:
        return False
    else:
        for i in range(len(lst)-1):
            if not abs(ord(lst[i])-ord(lst[i+1]))==num:
                return False
        return True