Using Python programming, create a function that takes a string representation o
ID: 3546307 • Letter: U
Question
Using Python programming, create a function that takes a string representation of one digit of the zip code, and returns the string of bars representing that digit. Then create a function that takes a string representation of a 5 digit zip code and returns the string of bars representing the entire zip code, including the check sum and frame bars. The check digit makes the sum of the 5 digits a multiple of 10. So if the zip code is 12111, the check digit would be 4. Use | and : for the tall and short bars.
Explanation / Answer
def returnBars(x):
if x=='0':
return '||:::'
if x=='1':
return ':::||'
if x == '2':
return '::|:|'
if x=='3':
return '::||:'
if x=='4':
return ':|::|'
if x=='5':
return ':|:|:'
if x=='6':
return ':||::'
if x=='7':
return '|:::|'
if x=='8':
return '|::|:'
if x=='9':
return '|:|::'
def main(y):
bars = returnBars(y[0]) + returnBars(y[1]) + returnBars(y[2]) + returnBars(y[3]) + returnBars(y[4])
checks = 10 - ((int(y[0]) + int(y[1]) + int(y[2]) + int(y[3]) + int(y[4])) % 10)
return (checks, bars)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.