Home > OS >  I defined a function and it says invalid syntax when I am using it [closed]
I defined a function and it says invalid syntax when I am using it [closed]

Time:09-28

I defined this function:

def decode(DECODE):
  dec = 0
  decoded = 0
  for i in range(len(DECODE)//2):
    dec = dec   2
    decoded = decoded   index(int(DECODE[dec-1])   int(DECODE[dec])
decode("1714212124")
print(decoded)

And I am getting this error:

decode("1714212124")
     ^

SyntaxError: invalid syntax

I don't understand why it says this even though I defined the function. Any help?

(Sorry if this post is bad it is my first)

CodePudding user response:

You're missing a parenthesis on the decoded affectation

decoded = decoded   index(int(DECODE[dec-1])   int(DECODE[dec])

You should close it and it'll be fine. It should be either

decoded = decoded   index(int(DECODE[dec-1]))   int(DECODE[dec])

or

decoded = decoded   index(int(DECODE[dec-1])   int(DECODE[dec]))

CodePudding user response:

# The number of numbers you typed is many, if you delete a number, the process will be successful like this:...
def decode(DECODE):
    dec = 0
    decoded = 0
    for i in range(len(DECODE)//2):
        dec = dec   2
        decoded = decoded   int(DECODE[dec-1])   int(DECODE[dec])


print(decode('171421212'))
  • Related