Validating Credit Card Numbers

  • + 1 comment

    I test ran my code and it passed all their default test but after submitting it still doesnt give me a good score it says i get 8.8 as my score. (angry face).

    heres my code class beginig: def init(self): self.switch = 0 self.results = []

    def initial(self):
        self.first = input()
    
        self.increamentor = 0
    
        self.rangenum = [1,2,3,4,5,6,7,8,9,0,'-']
        self.tt = []
    
        self.list1 =[]
        self.list2 = []
        self.list3 = []
        self.list4 = []
        self.list5 =[]
        self.list6 = []
        self.list7 = []
        self.list8 = []
        self.list9 =[]
        self.list0 = []
        self.list00 = []
        while self.increamentor < int(self.first):
            self.increamentor += 1
            self.tt[:] = []
            self.t = []
            ask_realInput = input()
            self.t.append(ask_realInput)
    
            for atom in self.t:
                for atomm in atom:
                    self.tt.append(atomm)
            if len(self.tt) != 16:
    
                if len(self.tt) != 19:
                    self.switch = 0
                else:
                    if self.tt[4] != '-':
                        self.switch = 0
    
                    else:
                        if self.tt[9] != '-':
                            self.switch = 0
                        else:
                            if self.tt[14] != '-':
                                self.switch = 0
                            else:
                                self.switch = 1
    
    
            else:
                self.switch = 1
    
            if self.switch == 0:
                self.results.append('Invalid')
            elif self.switch == 1:
                self.sec_init_()
    
    def sec_init_(self):
        testlist = []
        testlist2 = []
    
        for aromo in self.tt:
            testlist.append(aromo)
            testlist2.append(aromo)
    
        for ato in testlist:
    
            try:
                while '-' in testlist:
                    self.list00.append('-')
                    testlist.remove('-')
    
                while '0' in testlist:
                    self.list0.append('0')
                    testlist.remove('0')
    
                while '1' in testlist:
                    self.list1.append('1')
                    testlist.remove('1')
    
                while '2' in testlist:
                    self.list2.append('2')
                    testlist.remove('2')
    
                while '3' in testlist:
                    self.list3.append('3')
                    testlist.remove('3')
    
                while '4' in testlist:
                    self.list4.append('4')
                    testlist.remove('4')
    
                while '5' in testlist:
                    self.list5.append('5')
                    testlist.remove('5')
    
                while '6' in testlist:
                    self.list6.append('6')
                    testlist.remove('6')
    
                while '7' in testlist:
                    self.list7.append('7')
                    testlist.remove('7')
    
                while '8' in testlist:
                    self.list8.append('8')
                    testlist.remove('8')
    
                while '9' in testlist:
                    self.list9.append('9')
                    testlist.remove('9')
    
            except ValueError:
                pass
            all_list = [self.list0,self.list00,self.list1,self.list2,self.list3,self.list4,self.list5,self.list6,self.list7,self.list8,self.list9]
    
    
            self.er = []
            for every_atom in all_list:
                self.er[:] = []
                a = len(every_atom),':',every_atom
                self.er.append(a)
    
            ss = sorted(self.er, reverse=True)[0][0]
    
            if ss > 3:
                self.switch = 0
    
            else:
                self.switch = 1
    
    
    
    
    
        if self.switch == 0:
                self.results.append('Invalid')
        elif self.switch ==1:
            self.third_test()
    def third_test(self):
        if self.tt[0] != '4':
            if self.tt[0] != '5':
                if self.tt[0] != '6':
                    self.switch = 0
                else:
                    self.switch = 1
            else:
                self.switch = 1
        else:
            self.switch = 1
    
    
    
    
    
        if self.switch == 0:
            self.results.append('Invalid')
        elif self.switch ==1:
            self.fourth_test()
    
    def fourth_test(self):
        contents = ['1','2','3','4','5','6','7','8','9','0','-']
        do = []
        for everything in self.tt:
                if everything not in contents:
                    do.append(everything)
    
    
        if len(do) > 0:
            self.switch = 0
        else:
            self.switch = 1
    
        if self.switch == 0:
            self.results.append('Invalid')
        elif self.switch ==1:
            self.results.append('Valid')
    
    def end(self):
        for atom in self.results:
            print(atom)
    

    start = beginig() start.initial() start.end()