I need help with this code

! marks are driving me crazy because they do not make sense to me.
this is a simple code provided by a tutorial book i found, can someone explain it to me?

while password != "unicorn":
password = input("Password: ")
print("Welcome in")

according to this, the password would be unicorn, however, doesnt the exclamation point before the equal sign make password not equal to unicorn? This confuses the hell out of me

Thanks

Edit:
As a matter of fact this book gives projects, and some possible answers to the project, but doesnt really explain it.
If someone could break this down for me i would appreciate it


name = input("What is your UserName: ")
password = input("What is your Password: ")
print("To lock your computer type lock.")
command = None
input1 = None
input2 = None
while command != "lock":
command = input("What is your command: ")
while input1 != name:
input1 = input("What is your username: ")
while input2 != password:
input2 = input("What is your password: ")
print("Welcome back to your system!")

What does None mean?
and also what are the exclamations doing.
Why is command even there?
so lost.

Comments

  • : ! marks are driving me crazy because they do not make sense to me.
    : this is a simple code provided by a tutorial book i found, can
    : someone explain it to me?
    :
    [code]
    while password != "unicorn":
    password = input("Password: ")
    print("Welcome in")
    [/code]
    : according to this, the password would be unicorn, however, doesnt
    : the exclamation point before the equal sign make password not equal
    : to unicorn? This confuses the hell out of me

    [color=Blue]Simply put that code states the following:
    while the password entered is not "unicorn"
    prompt for the password
    [/color]
    :
    : Thanks
    :
    : Edit:
    : As a matter of fact this book gives projects, and some possible
    : answers to the project, but doesnt really explain it.
    : If someone could break this down for me i would appreciate it
    :
    :

    [color=Blue]Create your username[/color]
    [code]
    name = input("What is your UserName: ")
    [/code]

    [color=Blue]Create your password[/color]
    [code]
    password = input("What is your Password: ")
    [/code]

    [color=Blue]stuff... declaring variables[/color]
    [code]
    print("To lock your computer type lock.")
    command = None
    input1 = None
    input2 = None
    [/code]

    [color=Blue]while the command entered is not lock
    prompt for the user to enter a command[/color]
    [code]
    while command != "lock":
    command = input("What is your command: ")
    [/code]

    [color=Blue]Now the system is "locked" so how do you unlock it?
    By entering your name and password of course...

    while the input1 is not the username you created before
    prompt for the correct username
    [/color]
    [code]
    while input1 != name:
    input1 = input("What is your username: ")
    [/code]

    [color=Blue]while the input2 is not the password that you made
    prompt for the correct password[/color]
    [code]
    while input2 != password:
    input2 = input("What is your password: ")
    [/code]

    [color=Blue]unlocked!
    [/color]
    [code]
    print("Welcome back to your system!")
    [/code]
    :
    : What does None mean?

    [color=Blue]None means none. Nothing.
    Link~[/color] http://docs.python.org/c-api/none.html

    : and also what are the exclamations doing.

    [color=Blue]keeping you in a while loop until the correct information is entered.[/color]

    : Why is command even there?

    [color=Blue]command is there so that you can type in the command "lock"
    I would imagine that it could be expanded to allow for you to have other commands, but that is the only role it plays here.[/color]

    : so lost.
    :

  • Thanks a million i really appreciate it
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories