do you guys help newbies??

Wojtek Walczak gminick at hacker.pl
Wed Nov 27 11:05:24 EST 2002


Dnia Wed, 27 Nov 2002 15:53:20 GMT, Robin Munn napisał(a):
> You could also do this in one step, like:
>     gallonsPerTank = int(raw_input("Enter how many gallons..."))
It of course works, but there's a large amount of situations to think of.

---
import sys
try:
   while 1:
      a = raw_input("Put a digit here: ")
      if not a.isdigit():
         a = raw_input("Put a digit here: ")
      else:
         a = int(a)
         break
except:
   print sys.exc_info()[1]
   sys.exit()

print a
---

Any ideas to make it more reliable ?

-- 
[ ] gminick (at) underground.org.pl  http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]



More information about the Python-list mailing list