On 2011/07/01 09:30 AM, Ryan Kirk wrote:
Is there a way to limit raw_input to the hundredth decimal point?
For example, I'd like to allow the user to enter 5.75 but not 5.756:
dollars = raw_input("Please enter a dollar amount: $")
Thanks!
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
If you're using Windows you can use the msvcrt module which has an
implementation of getch() which gets 1 character at a time. Then you
would just scan your input 1 character at a time and as soon as a the
`.` is used you can limit it to 2 further key-strokes before you "ban"
input and carry on in your process flow.
--
Christian Witts
Python Developer
//
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor