All pastes #729357 Raw Edit

Stuff

public text v1 · immutable
·published 2007-10-07 21:54 UTC
rendered paste body
def verify_sin(sin):
    ''' This function will take in the user's sin number as paramter and check
    if the sin number is valid.  If it is valid it will return true, otherwise
    it will return false'''
    
    def add_input(odds): 
        return sum(int (v) for v in odds)
    
    #code is doing well so far... 
    sin = sin.replace ("-","")
    evens = add_input(sin[0:-1:2])
    
    odds_1 = [v for v in sin [1::2] if v < 5]
    odds_2 = [v for v in sin [1::2] if v >= 5]
    
    
    total = add_input(odds_1)*2 + sum(add_input(str(int(y)*2)) for y in odds_2)\
          + evens
    
    checksum_round = int(round (total,-1) + 10)
    
    if (checksum_round - total == sin[-1]):
        return True
    else:
        print checksum_round        
        print total
        print (checksum_round - total)
        print sin[-1]     
        return False


sin_num = str(raw_input("Please Enter your sin number: "))
print verify_sin(sin_num)

#use 046-454-286 as sin number (should return true)