Validate Credit Card Number
来源:互联网 发布:淘宝的禅 编辑:程序博客网 时间:2024/05/08 21:14
地址:http://www.codewars.com/kata/5418a1dd6d8216e18a0012b2/train/python
In this Kata, you will implement The Luhn Algorithm, which is used to help validate credit card numbers.
Given a positive integer of up to 16 digits, return true if it is a valid credit card number, and false if it is not.
Here is the algorithm:
If there are an even number of digits, double every other digit starting with the first, and if there are an odd number of digits, double every other digit starting with the second. Another way to think about it is, from the right to left, double every other digit starting with the second to last digit.
代码:
def validate(n): list = [] while(n>10): list.append(n%10) n /= 10 list.append(n) sum = 0 for i in range(0,len(list)): if( (len(list)%2 + i%2 ) % 2 == 0): list[i] *= 2 if list[i] > 9: list[i] -= 9 sum += list[i] if(sum%10 == 0): return 'true' else: return 'false'
0 0
- Validate Credit Card Number
- Credit card transaction
- JS Credit Card Mask
- test credit card account
- 【思维】Codeforces893D Credit Card
- codeforces893D Credit Card
- credit card fraud detection
- LA 6448 Credit Card Payment
- Shopping,Credit Card,and Something else
- Cancelled my American Express Credit card
- (贪心)【CF 893D】Credit Card
- CodeForces 893D Credit Card (贪心)
- code force 893D Credit Card
- Finance系列(4)之Credit Card
- Educational Codeforces Round 33 D. Credit Card
- Black Market in Stolen Credit Card Data Thrives on Internet
- How to Encrypt Credit Card Information in an SQL Database
- PayPal开发 -- REDICT CREDIT CARD PAYMNETS AND PCI compliance
- Hibernate工作原理
- nyoj1052 看美女2
- Plus one
- 通过上下文菜单的方式进行删除添加日记的操作
- 防外挂和防木马的通用解决方案
- Validate Credit Card Number
- ssh公钥的制作
- 高版本Eclipse取消js验证的办法
- AngularJS开发指南 中文教程
- 2014年7月到10月工作总结
- 1017 A Mathematical Curiosity
- 1012 u Calculate e
- <数据结构> 约瑟夫问题 (待补充完整)------------代表ADT小组
- 相同树判断