[Tutor] Python Programming exercise

bob gailer bgailer at gmail.com
Wed Jul 1 17:00:45 CEST 2009


Daniel Sato wrote:
> I have been going through some Python Programming exercises while 
> following the MIT OpenCourseWare Intro to CS syllabus and am having 
> some trouble with the first "If" exercise listed on this page:
>
> http://en.wikibooks.org/wiki/Python_Programming/Conditional_Statements#If_Exercises
>
> I have been able to make the module quit after entering a password 
> three times, but can't get it to quit right away after the correct one 
> is entered.  I know this is really basic, please forgive me.  I have 
> no programming experience and have just started going through these 
> tutorials.
>
> My code is here:
>
> http://python.pastebin.com/m6036b52e

When the code is that small please just put it in the body of your post. 
Save pastebin for (IMHO) anything over say 60 lines.

   1.
      password = "qwerty"
   2.
      guess = "0"
   3.
      count = 0
   4.
      while count != 3:
   5.
              guess = raw_input("Enter your password: ")
   6.
              guess = str(guess)
   7.
              if guess != password
   8.
                      print "Access Denied"
   9.
              count = count + 1       
  10.
              else:
  11.
                      print "Password Confirmed"


2 ways - either

   1.
      while count != 3 and guess != password:

or

   11.             print "Password Confirmed"
   12.             break



-- 
Bob Gailer
Chapel Hill NC
919-636-4239


More information about the Tutor mailing list