[Tutor] New to programming-Help
Darshan Gunawardena
janitor at gmail.com
Fri May 21 22:17:38 EDT 2004
I too am new to python. And I'm sure there must be many ways to
improve on this code. But for the moment I think it meets your
requirements.
count = 0
password = 'x'
while password != "secret" and count < 3:
password = raw_input("Enter your Password: ")
if password == "secret":
print "Welcome in."
else:
print "Incorrect Password"
count += 1
if count == 3:
print "Please come back when you remember your Password."
else:
raw_input("Press enter to exit.")
----- Original Message -----
From: brian illingworth <blugerz at yahoo.com>
Date: Fri, 21 May 2004 18:35:07 -0700 (PDT)
Subject: [Tutor] New to programming-Help
To: tutor at python.org
Hi I am new to this group and new to programming. I have
had this interest in learning to program because.......well
just because. It's just a curiosity that I have. The reason
I am starting with Python, well some of the websites I went
to recommended Python, so here I am.
Ok on to the question.
I am currently using the book "Python programming for
absolute beginners" by Michael Dawson. The program I am
working on is a password program....dont laugh I know it's
really simple to some, but I am kinda stuck. The book shows
how to code a password program like
this:
password = raw input("Enter your password:")
if password == "secret":
print "Access Granted"
else:
print "Access Denied"
raw input("Press the enter
key to exit")
Ok that is easy enough I understand what is going on here.
As the book goes on it also talks about elif, and while
loops. At the end of the chapter it gives various challenges
that the reader is asked to complete. One of the challenges
is to take the password program from above and change it so
that the user gets only three attempts to enter the correct
password. Well I ain't got it to work yet, I thought I came
close, but no cigar. This is what I have so far: #Limiting
password atempts to three
password = raw input("Enter your Password: ")
count = 0
while password != "secret":
print password = raw-input("Enter your Password: ")
count += 1
if password ==
"secret":
print "Welcome in."
elif count > 3:
print "Please come back when you remember your Password."
else:
raw input("Press enter to exit.")
Ok, I know I may be way off course here but any help would be
greatly appreciated. I dont want to get frustrated and say
the heck with it, especially if it is something minor.
Thanks in advance.
________________________________
Do you Yahoo!?
Yahoo! Domains - Claim yours for only $14.70/year
More information about the Tutor
mailing list