Sam writes down the numbers 1, 2, 3,..., 999
How many digits did Sam write, in total?
there are 1-digit, 2-digit, and 3-digit numbers
1-9 1-digit
10-99 2-digit
100-999 3 digit
now find how many numbers are in each category and multiply
Here is the Python code to calculate the number of digits:
def number_of_digits(n): if n < 10: return 1 elif n < 100: return 2 elif n < 1000: return 3 else: return 4 def total_number_of_digits(n): total_digits = 0 for i range(1, n + 1): total_digits +== number_of_digits(i) return total_digits print(total_number_of_digits(999))
The output of the code is 3515. Therefore, the answer is 3515 digits.