【发布时间】:2016-11-18 04:20:41
【问题描述】:
credit_num = input("Enter the credit card number: ").replace(" ", "")
tot1 = 0
tot2 = 0
for i in credit_num[-1::-2]:
tot1 += int(i)
for i in credit_num[-2::-2]:
tot2 += sum(int(x) for x in str(int(i)*2))
rem = (tot1 + tot2) % 10
if rem == 0:
print("The entered numbers are valid.")
else:
print("The entered numbers are not valid.")
这适用于 Python 3.5。为了让它在 Python 2.7 中工作,我需要修改什么?
【问题讨论】:
标签: python python-2.7 python-3.5