Feb-08-2024, 08:12 PM
"""I am new to python and programming in general, currently learning at an institution, which is why def is not even seen in my code. I am very lost right now, was tasked this:
Let us assume that we have the following credit card number issued by a
bank: (You can assume that user enter the credit card numbers separated by
hyphens)
2323-2005-7766-3554
For each of the tokens, you reverse the numbers (we remove the hyphen too)
3232 5002 6677 4553
For every token, you multiply by 2 every digit in the even position, i.e.
positions 2 and 4 (left to right for each token). We have the following new
four tokens:
3434 5004 612714 41056
I am stucked at the last part mentioned above. I am only able to get every single set of number separated by spaces.
Here's my code:
"""
I am stuck here. Can someone kindly help me out?
Thank you!
"""
Let us assume that we have the following credit card number issued by a
bank: (You can assume that user enter the credit card numbers separated by
hyphens)
2323-2005-7766-3554
For each of the tokens, you reverse the numbers (we remove the hyphen too)
3232 5002 6677 4553
For every token, you multiply by 2 every digit in the even position, i.e.
positions 2 and 4 (left to right for each token). We have the following new
four tokens:
3434 5004 612714 41056
I am stucked at the last part mentioned above. I am only able to get every single set of number separated by spaces.
Here's my code:
"""
print ("Welcome to DEF credit card company") print() ccnum_with_hyphens = input("Enter a credit card:") ccnum_without_hyphens = ccnum_with_hyphens.replace("-", " ") reversed_ccnum = "" for i in range(0, len(ccnum_without_hyphens), 5): reversed_ccnum += ccnum_without_hyphens[i+3] + ccnum_without_hyphens[i+2]+ ccnum_without_hyphens[i+1] + ccnum_without_hyphens[i] + " " print(reversed_ccnum) reversed_ccnum = reversed_ccnum.replace(" ", "") print(reversed_ccnum) # Convert the string to a list of characters chars = list(reversed_ccnum) # Iterate over the characters and multiply every digit at even positions by 2 for i in range(1, len(chars)-2, 4): chars[i] = str(int(chars[i]) * 2) for i in range(3, len(chars), 4): chars[i] = str(int(chars[i]) * 2) modified_ccnum = ' '.join(chars) print(modified_ccnum)"""
I am stuck here. Can someone kindly help me out?

"""