Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Programming Assignment #4: Barcode Generator
  4. CSC130
  5. Nicole Jenkins (kou669)
  6. October 14, 2016
  7. The purpose of this program is to prompt for a zip code and print a bar code.
  8. """
  9.  
  10. barcode= input(str("Insert barcode here."))
  11.  
  12.  
  13. #Digit 0-1
  14.  
  15. def digit(x):
  16. if int(barcode[x])==1:
  17. a = ":::||"
  18. elif int(barcode[x])==2:
  19. a = "::|:|"
  20. elif int(barcode[x])==3:
  21. a = "::||:"
  22. elif int(barcode[x])==4:
  23. a = ":|::|"
  24. elif int(barcode[x])==5:
  25. a = ":|:|:"
  26. elif int(barcode[x])==6:
  27. a = ":||::"
  28. elif int(barcode[x])==7:
  29. a = "|:::|"
  30. elif int(barcode[x])==8:
  31. a = "|::|:"
  32. elif int(barcode[x])==9:
  33. a = "|:|::"
  34. elif int(barcode[x])==0:
  35. a = "||:::"
  36.  
  37. return a
  38.  
  39. #Correction Digit
  40.  
  41. C = int(barcode[0])+int(barcode[1])+int(barcode[2])+int(barcode[3])+int(barcode[4])
  42.  
  43. def correction(x):
  44. if x < 10:
  45. B = 10 - x
  46. elif x < 20:
  47. B = 20 - x
  48. elif x < 30:
  49. B = 30 - x
  50. elif x < 40:
  51. B = 40 - x
  52. elif x < 50:
  53. B = 50 - x
  54.  
  55. if B==1:
  56. y = str(":::||")
  57. elif B==2:
  58. y = str("::|:|")
  59. elif B==3:
  60. y = str("::||:")
  61. elif B==4:
  62. y = str(":|::|")
  63. elif B==5:
  64. y = str(":|:|:")
  65. elif B==6:
  66. y = str(":||::")
  67. elif B==7:
  68. y = str("|:::|")
  69. elif B==8:
  70. y = str("|::|:")
  71. elif B==9:
  72. y = str("|:|::")
  73. elif B==0:
  74. y = str("||:::")
  75.  
  76. return y
  77.  
  78. print("|",digit(0),digit(1),digit(2),digit(3),digit(4),correction(C),"|")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement