Python Forum
Credit card number redacting script
Thread Rating:
  • 4 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Credit card number redacting script
#5
Thank you for clarifying.

In order for a function to properly return a value, when the function is called, it’s necessary to declare it as a variable. I see now.

I suppose it is also better practices to execute the module’s code below the if __name__ == "__main__": conditional.

With these ideas in mind, here is my script now:

def ccredact(card_string):
    redacted_num = card_string.replace(card_string[0:12], '**** **** **** ')
    return redacted_num

if __name__ == "__main__":
    card_string = str(input("Enter your fake credit card number: "))
    result = ccredact(card_string)
    print(result)
Here is @ichabod801’s script:

def ccredact(card_string):
    redacted_num = 'xxxx xxxx xxxx {}'.format(card_string[-4:])
    return redacted_num

if __name__ == "__main__":   
    card_string = str(input("Enter your fake credit card number: "))  
    result = ccredact(card_string)
    print(result)
They both run beautifully without issue.

I understand that performing the initial credit card number redaction task is much more Pythonic and elegant to simply use format slicing. But I think it would be enormously helpful for me to learn the syntax of enumerate if a kind soul on this message board would be able to whip together a loop with this special function in the context of my particular use case here. I’ve made a valiant attempt in my original post here. I sincerely tried. And it was an epic fail.

I’ve got an over abundance of guides and tutorials for enumeration such as the one on Read the Docs, on Programiz and on SO. These help.

But seeing someone demonstrate enumerate in the context of my fake credit card redaction task here I think would really help me understand the concept of enumeration better.

Thanks again, @ichabod801.
Reply


Messages In This Thread
Credit card number redacting script - by Drone4four - Jan-01-2019, 06:10 PM
RE: Credit card number redacting script - by Drone4four - Jan-15-2019, 02:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Music Python Script Repeating Number When Saving Facebook Photos ThuanyPK 2 211 May-13-2024, 10:59 PM
Last Post: ebn852_pan
  Having strange results from an RFID HID card reader - I'm stuck orbisnz 1 1,569 Mar-28-2022, 08:20 AM
Last Post: Larz60+
  SQL wild card use hammer 3 1,359 Jan-07-2022, 02:17 PM
Last Post: hammer
  Validating credit card frequency 8 4,334 Nov-05-2018, 07:36 PM
Last Post: frequency
  individual's ID card number in python danpek 2 3,842 Jun-14-2018, 04:07 PM
Last Post: DeaD_EyE
  Prime number Script Problem Codezters 4 4,147 Jul-21-2017, 03:07 AM
Last Post: Larz60+
  RAW IO disk access for SD Card shift838 1 8,656 Feb-27-2017, 03:35 AM
Last Post: Larz60+
  "Card Dealing" Python code 2.7 Paradoxalis 3 6,728 Nov-17-2016, 11:32 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020