Python Forum
simple register code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: simple register code (/thread-14884.html)



simple register code - aocii - Dec-22-2018

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")



RE: simple register code - ichabod801 - Dec-22-2018

The indentation is wrong. The elif's need to be at the same indentation level as the preceding if. Indentation matters in Python.


RE: simple register code - aocii - Dec-22-2018

(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