SHARE
TWEET

Untitled

a guest Oct 9th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from cs50 import get_int
  2.  
  3. def main():
  4.     while True:
  5.         num=get_int("Number: ")
  6.         if num > 0:
  7.             break
  8.  
  9.     checksum(num)
  10.  
  11. def checksum(n):
  12.     s1=s2=b=0
  13.     i=1
  14.  
  15.     while n>0:
  16.         digit=n%10
  17.  
  18.         if i%2==0:
  19.             d=digit*2
  20.  
  21.             if d<10:
  22.                 s1+=d
  23.  
  24.             else:
  25.                 s1+=d%10
  26.                 d/=10
  27.                 s1+=d
  28.  
  29.         else:
  30.             s2+=digit
  31.  
  32.         n/=10
  33.  
  34.         if n>=10:
  35.             a=n
  36.         b+=1
  37.  
  38.         i+=1
  39.  
  40.     s=s1+s2
  41.  
  42.     if s%10==0:
  43.         if b==15 and (a==34 or a==37):
  44.             print("AMEX")
  45.  
  46.         elif b==16:
  47.             if a in range(51,52):
  48.                 print("MASTERCARD")
  49.  
  50.             elif (a/10)==4:
  51.                 print("VISA")
  52.  
  53.     else:
  54.         print("INVALID")
  55.  
  56. if __name__ == "__main__":
  57.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top