Python Forum

Full Version: simple register code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi friends! I am new here, I am new at programming also. I know a little bit excell vba but I just started learning python. this is my first attempt to write code on python. I watched some videos on youtube. Somebody wrote the same code in python 3.5.1 but I wrote in 3.7.1 . And it gives this error
Error:
line 9 elif ( user != defuser) and (password == defpassword): ^ SyntaxError: invalid syntax


it works when I delete the anterior identation before 'elif' but this time 'elif' is not working. Can somebody say to me whats the wrong thing ?

defuser="userkid"
defpassword="1234"
while ( "true" ):
    user = input("type your user name:")
    password = input("type your password: ")
    if (user == defuser) and (password == defpassword):
        print ("welcome",user)
        break
        elif ( user != defuser)  and  (password == defpassword):
        print("your user name is invalid")
        elif  ( user == defuser)  and (password != defpassword):
        print("password invalid")
        print ("change password? (y/n) ")
        answer = input()
        if ( answer == "y" ):
            print("newpassword?")
            newpassword = input("newpassword?")
            print("please wait")
            defpassword = neewpassword
            print("new password has been created ")

        else :
            print("try again")
The indentation is wrong. The elif's need to be at the same indentation level as the preceding if. Indentation matters in Python.
(Dec-22-2018, 01:52 AM)ichabod801 Wrote: [ -> ]The indentation is wrong. The elif's need to be at the same indentation level as the preceding if. Indentation matters in Python.

Thanks, last night, before i go sleeping at 6 am, i tried it.I put elifs to same level as if, but forgot else and program didnt work because of this. but now i put them same order (if,elif,elif,else) and it works. Thanks