0

I am writing a small login script at school, but I'm having trouble with a certain line of code. Here is the full thing:

I have asked my teacher but she isn't quite sure herself.

#!/bin/python3

def login ():
  username = input ('username')
  password = input ('password')

if username == 'TestAcc'*
    if password == 'spectretest':
      print ('Welcome to the SpectreOS developer test system')
    else print ('invalid password')
else print ('invalid username')

*I get an error message on this line and I am not sure of the problem. Thanks for your help. :)

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
  • I think you are having some indentation issues. – lmiguelvargasf Sep 30 '19 at 14:32
  • Did you read the error message? What does it say to you? – Psytho Sep 30 '19 at 14:33
  • The first error I get if I try running your code is `SyntaxError: invalid syntax` on line 10. This is because, with an else condition, unless using the [one-line-if](https://stackoverflow.com/a/394814/1506086) syntax your else keyword must have `:` after it and the code after the else must be on a new line, indented one place to the right. – Rob Streeting Sep 30 '19 at 14:43
  • Unrelated: Use [`getpass.getpass()`](https://docs.python.org/3.5/library/getpass.html) to get the password, instead of `input()`, so the password is not shown on screen. – tobias_k Sep 30 '19 at 14:53

1 Answers1

1

Your code has several syntax issues, use the following:

def login ():
    username = input ('username')
    password = input ('password')

    if username == 'TestAcc':
        if password == 'spectretest':
            print ('Welcome to the SpectreOS developer test system')
        else: print ('invalid password')
    else:
        print ('invalid username')

Keep in mind that indentation in Python matters a lot. I strongly suggest you check more about Python's syntax. You can check many tutorials (articles, videos) out there in the web.

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228