Hey guys I'm fairly new to the programming world. For a school practice question I was given the following text and I'm suppose to convert this into code. I've spent hours on it and still can't seem to figure it out but I'm determine to learn this. I'm currently getting the error
line 7, in <module> if i % 2 == 0: TypeError: not all arguments converted during string formatting
What does this mean? I'm still learning loops and I'm not sure if it's in the correct format or not. Thanks for your time.
# GET user's credit card number
# SET total to 0
# LOOP backwards from the last digit to the first one at a time
# IF the position of the current digit is even THEN
# DOUBLE the value of the current digit
# IF the doubled value is more than 9 THEN
# SUM the digits of the doubled value
# ENDIF
# SUM the calculated value and the total
# ELSE
# SUM the current digit and the total
# ENDIF
# END loop
# IF total % 10 == 0 THEN
# SHOW Number is valid
# ELSE
# SHOW number is invalid
# ENDIF
creditCard = input("What is your creditcard?")
total = 0
for i in creditCard[-1]:
if i % 2 == 0:
i = i * 2
if i > 9:
i += i
total = total + i
else:
total = total + i
if total % 10 == 0:
print("Valid")
else:
print("Invalid")
creditCard[-1]gives you only the last element.creditCard[::-1]gives you the reverse ofcreditCardinstead (or just usereversed(creditCard)).