Please bear with my novice question as I just started learning Python (2.x). I'm trying to run a script where user could enter any number (e.g. ints or float) and the expected output would be the total digit numbers of that input number.
However, I've encountered the following problems and wondered if you could kindly help guide me through solving them. Many thanks!! :)
(problems)
In the printout message, the n value was always 0; whereas I wished to print out the original input number by the user.
I wished it would also process the float number. For now, a 'ValueError' was returned and the script was halted whenever a float number was entered.
If user enters any string or blank character, the script should ignore the input and repeat all over again asking for the user input until the number with correct format (i.e. either integer or float number) was entered.
def num_digits(n):
count = 0
while n:
count = count + 1
n = n/10
print 'The total digits for this number, ', n, ', are: ', count
return count
user_input = abs(int(raw_input('Enter a number:\n')))
num_digits(user_input)