vendredi 3 février 2017

If statement throws up a syntax error in python

I know this is not a big problem, but I am missing the trick somewhere.

Case I: There is an issue with the syntax of if, but I have used the correct set of conditional operators -

def candies(n, m):

 remain = m%n

 If remain == 0:         

    return m     

 Else:         

    return m -remain

Error:

file.py3 on line 3

If remain == 0:

        ^

SyntaxError: invalid syntax

Case II If I make the whole If statement in brackets so that it will return a true/false. It gives another error-

def candies(n, m):

remain = m%n

If (remain == 0):

    return m

Else:

    return m -remain

file.py3 on line 3

If (remain == 0):

                ^

SyntaxError: invalid syntax

Can you please help me out with the if syntax??

Aucun commentaire:

Enregistrer un commentaire