python - How do you add the sum of digits in a chosen value range? -


i trying print every value between 100 , 999 integers add equal 7 using for or while loop in python

here have far, once have 3 digits don't know do.

three_digit = range(100,999,1) dig1 = three_digit/10 dig2 = dig1/10 dig3 = dig1%10 lucky7 = (dig1+dig2+dig3) print '' ,lucky7, 

stack overflow discourages coding you, here hints:

break 3 digit number single digits

familiarize modulus (%) , floor division (//). these single out digits in number without having convert string.

loops

you'll want use range-based for loop, has syntax of for my_variable in range([enter range]). inside loop can add condition (if statement) prints out numbers match criteria.


Comments