How to print numbers which is divisible by 7 from 18 to 543 and sum their output? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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

4th Sep 2020, 8:24 PM
Mohammed Zubair
Mohammed Zubair - avatar
1 ответ
+ 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)
4th Sep 2020, 8:37 PM
ChaoticDawg
ChaoticDawg - avatar