Posted on:

21 Dec 2022

0

My Answer almost two hours of wasting time in making different function for no reason

card_no = 371449635398431

def splitter(num):
    som = 0
    s= 0
    k=0
    for i in str(num):
        if k%2== 0:    #this condition seperate out numbers
            som = som + int(i)
        else:
            s = int(i) * 2
            if s > 9:
                for j in str(s):
                    som += int(j)
            else:
                som += s
        k+=1

    if som%10== 0 :
        return True
    else:
        return False

print(splitter(card_no))

Came to this solution after making one function that makes a list of string soo i can iterate over it
then a function that multiply and again making big mistake to make it list(LOL)
and then one more function to add but nested list make that function hell soo think from scratch

0 answers ( 0 marked as helpful)

Submit an answer