main.py

 avatar
unknown
plain_text
3 years ago
1.0 kB
7
Indexable
#create function for basiccode
def funcbasic(a):
    total = 0
    for i in range(len(a)-1):
        lastV = int(a[i])
        total = total + lastV
    remainder = total%10
    lastV2 = int(a[len(a)-1])
    if remainder != lastV2:
        return False
    else:
        return True
#create function for positionalcode
def funcPositional(a):
    total = 0
    for i in range(len(a)-1):
        lastV = (int(a[i])*(i+1))
        total = total + lastV
    remainder = total%10
    lastV2 = int(a[len(a)-1])
    if remainder != lastV2:
        return False
    else:
        return True
#create function for UPCcode
def funcUPC(a):
    total = 0
    for i in range(len(a)-1):
        lastV = int(a[i]) * 3
        elastV = int(a[i])
        if i %2 == 0:
            total = total +lastV
        else:
            total = total + elastV

    remainder = total % 10
    if remainder != 0:
       remainder = 10 - remainder
    if remainder != int(a[len(a)-1]):
        return False
    else:
        return True


Editor is loading...