Learn How to Work with Numbers and Strings by Implementing the Luhn Algorithm - Step 13

Reverse the order of the digits in the last four digits of card_number , by using a slice with a step of -1 . You can use either negative or positive indices for the start and end indices.

I know what the answer is but i just don’t understand why the last digit in card_number[0 : 4 : 2] is a -1 when reversing the number 2 would be -3

def verify_card_number(card_number):
sum_of_odd_digits = 0
card_number_reversed = card_number[0 : 4 : 2]
print(card_number_reversed)

Could you link to the challenge in question?

If I understand your question correctly, this step isn’t really trying to show the exact equivalent of [0:4:2] slice, when the last number is negative.

no they’re all negative numbers, I understand the first two digits which are -1, -5 but not the third digit which is -1 when a 2 in reverse would be -3 not -1

-1 is the last digit
-5 is the 4th last digit
-1 indicates to go 1 digit at a time, backwards

It says to reverse the last 4 digits, not to go by 2s

2 Likes

thank you for explaining!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.