PDA

View Full Version : defaulting input



ki4jgt
May 9th, 2011, 12:01 AM
When I a = input("how many") how can I default it to 1 if the user enters a word instead of a number?

Tony Flury
May 9th, 2011, 08:22 AM
which language ?

If it was python I would use isdigit



a = input("How Many")
if NOT a.isdigit():
a = 1

isdigit checks that every character is a number

Note - the above wont work with decimal points.

ki4jgt
May 9th, 2011, 11:28 AM
exactly what I needed thanks.