Python program I made

Started by
8 comments, last by biggjoee5790 17 years, 1 month ago
hi guys Im sorry If im being annoying by asking everyone to tell me if my Python programs are correct but I just want some feedback to see If Im progressing correctly. The exercise I had to do was: "Write a program that asks the user for a Login Name and password. Then when they type Lock, they need to type in there name and password to unlock the program." heres what I did:
loop = "loop"
while loop == "loop":
    LoginName = "Welcome"
    while LoginName != "Login":
        LoginName = raw_input("Login Name? ")
    Password = "Hello"
    while Password != "Pass":
        Password = raw_input("Password? ")
    print "Welcome!!"    
    LOCK = "food"
    while LOCK != "Lock":
        LOCK = raw_input("Type 'Lock' to lock system: ")
        print "System Locked, Input Login Name and Password to unlock."
What do you think of this program? Is it the right way to execute this type of program? If you want to try it the LoginName is Login and the Password is Pass. I wanted to know if I went about making the entire program loop the correct way, I used a variable called loop and set it as a while statement (as you can see at the top) The book im using didnt say to do it like that but I thought it would be a good idea and it seems to work, I just wasnt sure about how the multiple indents would work.. thanks in advance
Advertisement
oops.. for some reason the indents in my program arent showing up in the post. any idea how I can make them show? The program doesnt really make sense without them
Surround your code with [ source] and [/ source] tags, minus the spaces.
ahh there we go, now you guys can see it
all I can say is string comparisons are normally slower than simple data type comparisons(boolean/int/etc), and the line lock=food is kind of a strange one..(couldn't use lock="" or make it a boolean?)
Quote:"Write a program that asks the user for a Login Name and password. Then when they type Lock, they need to type in there name and password to unlock the program."

As I read this, the user should first be allowed to choose the login name and password, and then use them to unlock the program. Makes a bit more sense than what you have done.

Also, why does the assignment mix up "their" and "there"? Seems odd.
Quote:Original post by eedok
all I can say is string comparisons are normally slower than simple data type comparisons(boolean/int/etc), and the line lock=food is kind of a strange one..(couldn't use lock="" or make it a boolean?)



well first of all I havent learnt boolean yet, the exercise wants you to make the program using the skills you learned in the chapter. The chapter was about "while" statements. Im guessing that as I learn more I can make this program better. Oh yea making lock = food was pretty dumb, I just stuck any word in there as a placeholder (in the chapter, the author does the same thing except he uses "foobar" as a placeholder.

And as to why the author confuses there and their, I really have no idea lol. If you want to check out the book its free online at Wikipedia, I believe its called A Non-Programmers Guide to Python, or something like that. Im using it because its the only book I found that didnt really require any prior experience in programming
Boolean is a binary logic type. It has two values, True and False.

    while LOCK != "Lock":        LOCK = raw_input("Type 'Lock' to lock system: ")        print "System Locked, Input Login Name and Password to unlock."


(In reference to the above:) Unless I misunderstand, couldn't something like the following be done with that:
Program prints: Type 'Lock' to lock system: User enters:    SomethingThatIsn'tLockProgram prints: System Locked, Input Login Name and Password to unlock.Program prints: Type 'Lock' to lock system:User enters:    Lock


Because you print the "System Locked" message regardless of whether or not the user actually entered "Lock" (and therefore, regardless of whether or not the system actually is locked). I think, assuming my virtually non-existent knowledge of Python is right, that by reducing the indentation of the print statement by one you would eliminate this bug.
[TheUnbeliever]
Ahh yes you are right, It will print Program Locked regardless of what they type, that was my mistake. Youre correct about the indent, If I bring the indent back on the print line it will work correctly, only printing when LOCK is entered.
Quote:Original post by Wiggin
Quote:"Write a program that asks the user for a Login Name and password. Then when they type Lock, they need to type in there name and password to unlock the program."

As I read this, the user should first be allowed to choose the login name and password, and then use them to unlock the program. Makes a bit more sense than what you have done.

Also, why does the assignment mix up "their" and "there"? Seems odd.


Do you think you can show me how to write this so that it allows the user to create their own Username and password?

This topic is closed to new replies.

Advertisement