On Tue, Jun 7, 2011 at 11:26 PM, Matthew Brunt <mbrun...@gmail.com> wrote: > i'm very new to python (currently going through a python for beginners > book at work to pass the time), and i'm having trouble with an if > statement exercise. basically, i'm creating a very simple password > program that displays "Access Granted" if the if statement is true. > the problem i'm having is that no matter what i set the password to, > it seems like it's ignoring the if statement (and failing to print > "Access Granted"). the code is copied below. i'm pretty sure it's my > own programming ignorance, but i would greatly appreciate any > feedback.
Actually, no, this case it's not your ignorance. What is probably going on is that you are using Python 2, but the book is going with Python 3. I won't get into the details, but the function that does what input() does in Python 3, is called raw_input() in Python 2 (and the Python 2 input() function is advised against using for security reasons). Probably if you change input to raw_input in your program, it does do what you want it to do. > # Granted or Denied > # Demonstrates an else clause > > print("Welcome to System Security Inc.") > print("-- where security is our middle name\n") > > password = input("Enter your password: ") > > if password == "a": > print("Access Granted") > > input("\n\nPress the enter key to exit.") > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- André Engels, andreeng...@gmail.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor