0
How to print numbers which is divisible by 7 from 18 to 543 and sum their output?
How to add your output result and show as the final answer
1 Resposta
+ 8
You can use the modulo operator to check if a number is divisible by another number. It will have a result of 0 when true.
num % 7 == 0 # True if divisible False otherwise
Then just use a variable to total up the sum.
Use:
for in range(start, stop):
to loop over the numbers from 18 (inclusive) to 543 (exclusive, add 1 to include)