[Tutor] Exeption errors

Kevin python_newbie at vedorian.com
Sat Aug 21 19:28:09 CEST 2004


I just changed the code to look like this and it works good. Is there a simpler way to do this?

def one():
    x=raw_input("Enter a number: ")
    try:
        while int(x) != 1:
            print "Thats not 1"
            x=raw_input("Enter a number: ")
    except ValueError:
            print "that is not a number"
            one()
    else:
            print "Thats the number 1!!"

one()
  ----- Original Message ----- 
  From: Kevin 
  To: Python 
  Sent: Saturday, August 21, 2004 1:23 PM
  Subject: [Tutor] Exeption errors


  I am playing around with Exeption Errors this is the code I did:
  x=raw_input("Enter a number: ")
  try:
      while int(x) != 1:
          print "Thats not 1"
          x=raw_input("Enter a number: ")
  except ValueError:
          print "that is not a number"

  it works to a point when I type in a number that is not a one it will keep saying Thats not 1, but when I put in a letter it will say that is not a number and then exit the program. How do I make it look again?

  Thanks
  Kevin


  ---
  Outgoing mail is certified Virus Free.
  Checked by AVG anti-virus system (http://www.grisoft.com).
  Version: 6.0.740 / Virus Database: 494 - Release Date: 8/16/04


------------------------------------------------------------------------------


  _______________________________________________
  Tutor maillist  -  Tutor at python.org
  http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040821/0aff75af/attachment.html


More information about the Tutor mailing list