Help with SyntaxError

Hello,

Can anyone help me with this? I keep getting the message SyntaxError: ‘return’ outside function.

def repToDecimal(str,base):

    result = 0

#initializing a dictionary

dict={‘0’:0,‘1’:1,‘2’:2,‘3’:3,‘4’:4,‘5’:5,‘6’:6,‘7’:7,‘8’:8,‘9’:9,‘A’:10,‘B’:11,‘C’:12,‘D’:13,‘E’:14,‘F’:15}

for i in str:

n = dict[i]

result = base * result + n

return result

#calling the method and displaying the result

print(repToDecimal(‘10’,10))

print(repToDecimal(‘10’,8))

print(repToDecimal(‘10’,2))

print(repToDecimal(‘10’,16))

It’s your indentation.

def my_function(args...):
  #do something
  return something

and not

def my_function(args...):
  #do something
return something

Also welcome to the forums :slight_smile:
Please see this note on formatting posts for future use: [How to] Format code in posts - #7

1 Like