Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Programming Assignment #4: Barcode Generator
- CSC130
- Nicole Jenkins (kou669)
- October 14, 2016
- The purpose of this program is to prompt for a zip code and print a bar code.
- """
- barcode= input(str("Insert barcode here."))
- #Digit 0-1
- def digit(x):
- if int(barcode[x])==1:
- a = ":::||"
- elif int(barcode[x])==2:
- a = "::|:|"
- elif int(barcode[x])==3:
- a = "::||:"
- elif int(barcode[x])==4:
- a = ":|::|"
- elif int(barcode[x])==5:
- a = ":|:|:"
- elif int(barcode[x])==6:
- a = ":||::"
- elif int(barcode[x])==7:
- a = "|:::|"
- elif int(barcode[x])==8:
- a = "|::|:"
- elif int(barcode[x])==9:
- a = "|:|::"
- elif int(barcode[x])==0:
- a = "||:::"
- return a
- #Correction Digit
- C = int(barcode[0])+int(barcode[1])+int(barcode[2])+int(barcode[3])+int(barcode[4])
- def correction(x):
- if x < 10:
- B = 10 - x
- elif x < 20:
- B = 20 - x
- elif x < 30:
- B = 30 - x
- elif x < 40:
- B = 40 - x
- elif x < 50:
- B = 50 - x
- if B==1:
- y = str(":::||")
- elif B==2:
- y = str("::|:|")
- elif B==3:
- y = str("::||:")
- elif B==4:
- y = str(":|::|")
- elif B==5:
- y = str(":|:|:")
- elif B==6:
- y = str(":||::")
- elif B==7:
- y = str("|:::|")
- elif B==8:
- y = str("|::|:")
- elif B==9:
- y = str("|:|::")
- elif B==0:
- y = str("||:::")
- return y
- print("|",digit(0),digit(1),digit(2),digit(3),digit(4),correction(C),"|")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement