+ 2
For loops
How do I compute all multiples of 3&5 in a range?
4 Respuestas
+ 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)
+ 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.
+ 2
Python requires formatting of blocks with indentation. Work issue :
https://code.sololearn.com/cl3ThlJYtX6Q/?ref=app
0
I'm lost. Is this python?