0

I tried to make a checksum function but my tests returned None instead of the expected output. Can you point out where I went wrong and how to correct it? I am trying to get a numerical sum out of a bunch of strings in the test code.

def string_checksum(data):
    partialchecksum = 0
    for i in data:
        if i is int:
            partialchecksum += i
        else:
            def tobits(i):
                result = []
                strsum = 0
                for c in i:
                    bits = bin(ord(c))[2:]
                    bits = '00000000'[len(bits):] + bits
                    result.extend([int(b) for b in bits])   
                    strsum = sum(result)
    checksum = partialchecksum + strsum
    return checksum
## Heading ##
Matthew Miller
  • 29
  • 1
  • 1
  • 6
  • You declared the function `tobits` and you're never calling it... further, in the `if` case the variable `strsum` is not defined and you're trying to use it after the loop. And last, please don't assume that we'll understand what you want to do by reading your code... – Nir Alfasi Dec 02 '17 at 17:27
  • do you think I could fix this with a main function? – Matthew Miller Dec 02 '17 at 17:35

0 Answers0