Jan-15-2019, 02:40 AM
(This post was last modified: Jan-15-2019, 08:48 PM by Drone4four.)
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
With these ideas in mind, here is my script now:
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.
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.