[Tutor] New to programming-Help

Glen Wheeler gew75 at hotmail.com
Fri May 21 22:31:51 EDT 2004


  Hi Brian,

  Just before I say anything, please try to send plain text e-mails.
Thanks.
  You haven't provided a traceback, so I don't really know what is wrong
with the programs below apart from some basic syntax.
  The most glaring is that the function raw_input(...) is just one word with
an underscore in the middle; this would be causing errors.  So, for example,
(untested)


print 'Welcome to the Miracle Aging salon!'

name = raw_input("Please enter your name >> ")
print 'Welcome', name+'!'

inputOK = false
while not inputOK:
    age = raw_input("Please enter your age >> ")
    try:
        age = int(age)
        if age > 0:
            inputOK = true
        else:
            print "No cheating ;)"
    except:
        print "Integral ages only please"

inputOK = false
while not inputOK:
    dAge = raw_input("Please enter your *desired* age >> ")
    try:
        dAge = int(age)
        if dAge > 0 and dAge < age:
            inputOK = true
        else:
            print "Sorry, our products only work to provide non-negative
ages\n *less* than your current age"
    except:
        print "Integral ages only please"

for i in range(age-dAge):
    print "Shaving off 1 year..."
    print "You are now", age-i-1, "years old!"

print "De-aging process complete."

print "Congratulations", name, "you are now", dAge, "years old!"

  This example, which I just concocted, would be a good one to split into
functions.  You might notice that the two while loops asking for input look
very simnilar; they are perfect candidates for turning into functions.
Allowing the program to be run multiple times with multiple clients would be
another good exercise.
  Anyway, I'll stop here ;).  Feel free to ask any more questions, and
apologies for any typos in the above code.

-- 
Glen
----- Original Message ----- 
From: brian illingworth
To: tutor at python.org
Sent: Saturday, May 22, 2004 11:35 AM
Subject: [Tutor] New to programming-Help


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



_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list