Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple register code
#1
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")
Reply
#2
The indentation is wrong. The elif's need to be at the same indentation level as the preceding if. Indentation matters in Python.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 288 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 470 Nov-07-2023, 04:32 PM
Last Post: snippsat
  help me simple code result min and max number abrahimusmaximus 2 900 Nov-12-2022, 07:52 AM
Last Post: buran
  Pymodbus Write value to register stsxbel 10 8,058 Aug-18-2022, 01:42 PM
Last Post: DeaD_EyE
  Simple encoding code ebolisa 3 1,435 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,783 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Simple syntax to asynchronously get access to MODBUS register orion67 1 2,834 Jan-22-2022, 12:40 PM
Last Post: orion67
  Simple code question about lambda and tuples JasPyt 7 3,284 Oct-04-2021, 05:18 PM
Last Post: snippsat
  My simple code don't works !! Nabi666 1 1,597 Sep-06-2021, 12:10 PM
Last Post: jefsummers
Sad SyntaxError: from simple python example file from mind-monitor code (muse 2) warmcupoftea 4 2,806 Jul-16-2021, 02:51 PM
Last Post: warmcupoftea

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020