Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. import math
  2. import sys
  3.  
  4. total = 0
  5. dict = {"1" : ":::||",
  6.         "2" : "::|:|",
  7.         "3" : "::||:",
  8.         "4" : ":|::|",
  9.         "5" : ":|:|:",
  10.         "6" : ":||::",
  11.         "7" : "|:::|",
  12.         "8" : "|::|:",
  13.         "9" : "|:|::",
  14.         "0" : "||:::"}
  15.        
  16. def checksum(zip):
  17.     global total
  18.     for i in zip:
  19.         total += int(i)
  20.     if total % 10 == 0:
  21.         return ''
  22.     else:
  23.         for num in range(1,10):
  24.             if (total+num) % 10 == 0:
  25.                 return str(num)
  26.    
  27. def barcode(zip):
  28.     string = str(checksum(zip))
  29.     zip = zip + string
  30.     print("|", end = "")
  31.     for i in zip:
  32.         print(dict[i], end = "")
  33.     print("|")
  34.    
  35. if __name__ == "__main__":
  36.     print("Welcome to Bar Code Generator")
  37.     while True:
  38.         user = input("Enter Zip Code (exit to quit):\n")
  39.         if user == "exit":
  40.             print("Thanks for using me.")
  41.             sys.exit()
  42.         else:
  43.             output = barcode(user)
  44.             print("Bar Code:\n",output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement