+ 2

For loops

How do I compute all multiples of 3&5 in a range?

13th Sep 2019, 12:02 PM
Onimisi
Onimisi - avatar
4 Answers
+ 2
Python # Calculates sum of multiples ofĀ  # a number upto N def calculate_sum(a, N): Ā Ā  Ā Ā Ā Ā # Number of multiples Ā Ā Ā Ā m = N / a Ā Ā  Ā Ā Ā Ā # sum of first m natural numbers Ā Ā Ā Ā sum = m * (m + 1) / 2 Ā Ā  Ā Ā Ā Ā # sum of multiples Ā Ā Ā Ā ans = a * sum Ā Ā  Ā Ā Ā Ā print("Sum of multiples of ", a, Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā " up to ", N, " = ", ans) Ā Ā  # Driver Code calculate_sum(7, 49)
13th Sep 2019, 12:17 PM
Роман Š›ŃŒŠ²Š¾Š²
Роман Š›ŃŒŠ²Š¾Š² - avatar
+ 2
Роман Š›ŃŒŠ²Š¾Š² Nice code šŸ‘ Please verify code is runnable, it didn't run when I checked it out. There are invalid characters that prevents the code to run. Try viewing from a web browser, those characters will show up. (Edit) Alternatively view the code in a code editor, then switch encoding to ANSI. Those characters will also show up then.
13th Sep 2019, 1:05 PM
Ipang
+ 2
Python requires formatting of blocks with indentation. Work issue : https://code.sololearn.com/cl3ThlJYtX6Q/?ref=app
13th Sep 2019, 1:51 PM
Роман Š›ŃŒŠ²Š¾Š²
Роман Š›ŃŒŠ²Š¾Š² - avatar
0
I'm lost. Is this python?
13th Sep 2019, 12:16 PM
Onimisi
Onimisi - avatar