Alright, I am working on this for an assignment and I cannot seem to figure out where I went wrong...

My first problem, whenever I input the CC number, the only one it accepts is the last one in my text file...

My second problem, when it does accept a CC number and display the proper text in the code below, it doesn't break out of it properly...I tried adding breaks to random spots, but it doesn't seem to be working.

Any help would be appreciated. :)

selection = raw_input("Are you are returning customer? [Y/N] ")

while True:
     if selection.upper() == "Y":
          while True:
               try:
                    ccNumberCheck = int(raw_input("Please enter the credit card number last used here: "))
                    if len(str(ccNumberCheck)) == 16:
                         ccFile = open("cat.txt", "r")
                         for line in ccFile:
                              items = line.split(",")
                              if str(ccNumberCheck) == items[2]:
                                   title = items[0]
                                   lastName = items[1]
                                   ccNumber = items[2]
                                   print "Welcome back, " + title + ". " + lastName + "!"
                                   break
                              
                         ccFile.close()
                         break
               except ValueError:
                    print "Sorry, that is an incorrect value."

I didn't see an edit button, but I got it solved.
I had to strip "\n" from the file lines...that is why the last number was the only one to work.

And it continuously looped because I didn't have anything else in my loop but that... :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.