4

I'm working on a project to create a postal bar code out of an inputted 5 digit zipcode. When I run the code, I get an error that says "can't assign to function call". What is wrong with the code, and how do I fix it?

zipcode = input("What is your 5 digit zipcode?")
s = zipcode.split(",")

def barcode(a):                                                        
    if a==0:
        print("||:::") 
    elif a==1:
        print(":::||")
    elif a==2:
        print("::|:|")
    elif a==3:
        print("::||:")
    elif a==4:
        print(":|::|")
    elif a==5:
        print(":|:|:")
    elif a==6:
        print(":||::")
    elif a==7:
        print("|:::|")
    elif a==8:
        print("|::|:")
    elif a==9:
        print("|:|::")

for barcode(a) in s:
    print(barcode(a))
1
  • I would suggest changing total=int(zipcode[0])... to total=sum(int(x) for x in zipcode). Much more readable and way easier for you to type. Commented Oct 19, 2016 at 23:18

2 Answers 2

2

Your error is here:

for barcode(a) in s:

It's invalid syntax because the name bound in a for loop has to be a python identifier.

You were probably trying for something like this instead:

for the_zipcode in s:
    print(barcode(the_zipcode))
Sign up to request clarification or add additional context in comments.

4 Comments

print(the_zipcode(barcode)) TypeError: 'str' object is not callable
So i changed what you suggested and its giving me this^
I see now ha, sorry, BUT Im trying to call the function "barcode(a)" in the for loop to print the "::|:|:" things per digit in the inputted zipcode... when I use "the_zipcode" it just prints the zipcode inputted
You are god of python please help... I will sacrifice my firstborn to your mightiness...
0

I am fairly certain your problem is your use of s=zipcode.split(","). What that does is split the string that is put in by the user (if you're using python 3) into an array of strings, where each element is delimited by a comma. For example:

'11111'.split(',') # ['11111']
'11111,12345'.split(',') # ['11111', '12345']

That is almost certainly not what you want, since you're asking the user to input a 5-digit zip code. If you just use the input directly, I think you'll get what you want.

That is:

zipcode=input("What is your 5 digit zipcode?")
# . . .
for digit in zipcode:
  print(barcode(digit)) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.