Brayden Hark
Brayden Hark

Reputation: 47

can't assign to function call Error-Python

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))

Upvotes: 4

Views: 290

Answers (2)

Steven Oxley
Steven Oxley

Reputation: 6723

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)) 

Upvotes: 0

wim
wim

Reputation: 362587

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))

Upvotes: 2

Related Questions