Search code examples
python-3.xsyntaxsyntax-error

SyntaxError: invalid syntax, I don't know how to fix this code. What's wrong with it? And how to solve it?


The part of the code that produced the error

def modinverse(a,26):
  
  for x in range(0,26):
    if(((a%26)*(b%26))%26 == 1):
      return x
  return -1

print(modinverse(a,26))

Here is the error I got

  File "main.py", line 51
    def modinverse(a,26):
                     ^
SyntaxError: invalid syntax

I checked,it looks good. The spellings are fine, brackets and stuff are closed, I don't know what to do. I can't see what's gone wrong. I ran this on replit.


Solution

  • Maybe def modinverse(a,26) should be something like def modinverse(a,b) or def modinverse(a,b=26):?

    In the first case you are declaring a parameter with the name 26.