Junior
219
Describe an algorithm that counts the number of numbers with the digit 7 in the range from 1 to 1000.
Answer from AI
sobes.tech AI
# Initialize counter
count = 0
# Iterate over numbers from 1 to 1000 (inclusive)
for number in range(1, 1001):
# Convert number to string for easy digit check
number_str = str(number)
# Check if the string contains the digit '7'
if '7' in number_str:
# Increment counter if '7' is found
count += 1
# Result - number of numbers containing the digit 7 in the range
# print(count) # Output for debugging