Python

Moderators: None (Apply to moderate this forum)
Number of threads: 474
Number of posts: 1166

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
I need help with this code Posted by Gromiqu1234 on 18 Jan 2011 at 9:54 PM
! 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.
Report
Re: I need help with this code Posted by nebgast on 26 Jan 2011 at 5:42 AM
: ! 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

Simply put that code states the following:
while the password entered is not "unicorn"
prompt for the password

:
: 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
:
:

Create your username
name = input("What is your UserName: ")


Create your password
password = input("What is your Password: ")


stuff... declaring variables
print("To lock your computer type lock.")
command = None
input1 = None
input2 = None


while the command entered is not lock
prompt for the user to enter a command

while command != "lock":
    command = input("What is your command: ")


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

while input1 != name:
    input1 = input("What is your username: ")


while the input2 is not the password that you made
prompt for the correct password

while input2 != password:
    input2 = input("What is your password: ")


unlocked!

print("Welcome back to your system!")

:
: What does None mean?

None means none. Nothing.
Link~
http://docs.python.org/c-api/none.html

: and also what are the exclamations doing.

keeping you in a while loop until the correct information is entered.

: Why is command even there?

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.


: so lost.
:

Report
Re: I need help with this code Posted by Gromiqu1234 on 7 Feb 2011 at 8:41 PM
Thanks a million i really appreciate it



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.