Public feed
#727553
def verify_sin(sin): count = -1 sum1 = 0 sum2 = 0 '''Given a string argument returns True if the string entered represents a valid sin number. Otherwise returns False.''' for digit in sin: if digit != '-':#Prevents '-' from being counted as a numerical digit. count += 1 #Updates the count to reflect the position of the digit. if digit != '-' and count / 2 == count / 2.0 and count < 8: #Prevents # -'s from being treated like numbers and ensures that only every # other number is used (excluding the checksum). sum1 += int(digit) if digit!='-' and count / 2 != count / 2.0 and count < 8 and int(digit)\ * 2 < 10: sum2 = sum2 + (int(digit) * 2) #Multiplies the remaining digits by 2 #and sums them, provided the product is a single digit value. if digit != '-' and count / 2 != count/2.0 and count < 8 and int(digit)\ * 2 >= 10: sum2 = sum2 + int(digit) * 2 / 10 + int(digit) * 2 % 10 #Takes the #sum of any digits whose product when multiplied by two produces #a two digit number, summing the digits separately. sum_final = sum1 + sum2 sum_final = sum_final % 10 sum_final = 10 - sum_final return str(sum_final) == sin[10]