Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import sys
- total = 0
- dict = {"1" : ":::||",
- "2" : "::|:|",
- "3" : "::||:",
- "4" : ":|::|",
- "5" : ":|:|:",
- "6" : ":||::",
- "7" : "|:::|",
- "8" : "|::|:",
- "9" : "|:|::",
- "0" : "||:::"}
- def checksum(zip):
- global total
- for i in zip:
- total += int(i)
- if total % 10 == 0:
- return ''
- else:
- for num in range(1,10):
- if (total+num) % 10 == 0:
- return str(num)
- def barcode(zip):
- string = str(checksum(zip))
- zip = zip + string
- print("|", end = "")
- for i in zip:
- print(dict[i], end = "")
- print("|")
- if __name__ == "__main__":
- print("Welcome to Bar Code Generator")
- while True:
- user = input("Enter Zip Code (exit to quit):\n")
- if user == "exit":
- print("Thanks for using me.")
- sys.exit()
- else:
- output = barcode(user)
- print("Bar Code:\n",output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement