在for循环开始的else语句之后,它使语法始终无效
for i in range(0,15,2):
^
SyntaxError: invalid syntax
我更改了for循环,并在else语句后更改了该错误
from cs50 import get_string
inp = get_string("Number: \n")
out = "INVALID"
state = ""
sum = 0
if len(inp) == 15:
state="AMEX"
for i in range(1, 15, 2):
if (int(inp[i]) * 2) > 9 :
sum += (int(inp[i]) * 2) % 10
sum += (int(inp[i]) * 2) // 10
else:
sum = sum + (int(inp[i]) * 2
for i in range(0,15,2):
sum += int(inp[i])
if sum % 10 == 0:
out = state
print(out)
else:
print(out)