Invalid Syntax


#1

Hello I'm working on a log in code. But when i added the else function if the password is false it gives a invalid syntax at print.

Here is the code the error that it gives at print is 'Invalid Syntax'


#2

When you start a block (if, else, elif, for ... in ...) you have to add a colon:

else: print('Password incorrect')

On the next line you have elif statement. This is incorrect. else reads as otherwise, so you can't add elif after else. To fix this, you need to add indentation before the else at line 12.


#3

could you send me a example i'm trying to place them but i doesn't work.


#4

This is corrected version of your code:

print('Hello input your name')
Name = input()
if Name == 'Erdinc':
  print('Hello Erdinc')
  print('input your password')
  PasswordE = input()
  if PasswordE == '2003':
    print('Password correct')
    print('Welcome at the menu')
  else: print('Password incorrect') # colon and indentation
elif Name == 'Dan':
  print('Hello Dan')
  print('input your password')
  PasswordE = input()
  if PasswordE == '2004':
    print('Password correct')
    print('Welcome at the menu')
  else: print('Password incorrect')

#5

Thank you it worked:D


#6

You're welcome :slight_smile: